當前位置: 首頁>>代碼示例>>C#>>正文


C# PooledRedisClientManager.GetReadOnlyClientPoolActiveStates方法代碼示例

本文整理匯總了C#中ServiceStack.Redis.PooledRedisClientManager.GetReadOnlyClientPoolActiveStates方法的典型用法代碼示例。如果您正苦於以下問題:C# PooledRedisClientManager.GetReadOnlyClientPoolActiveStates方法的具體用法?C# PooledRedisClientManager.GetReadOnlyClientPoolActiveStates怎麽用?C# PooledRedisClientManager.GetReadOnlyClientPoolActiveStates使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ServiceStack.Redis.PooledRedisClientManager的用法示例。


在下文中一共展示了PooledRedisClientManager.GetReadOnlyClientPoolActiveStates方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Main2

        static void Main2(string[] args)
        {
            var sbLogFactory = new StringBuilderLogFactory();
            LogManager.LogFactory = sbLogFactory;
            var log = LogManager.GetLogger(typeof(Program));

            var clientManager = new PooledRedisClientManager(new[] { "localhost" })
            {
                PoolTimeout = 1000,
            };

            var mqHost = new RedisMqServer(clientManager, retryCount: 2);

            var msgsProcessed = 0;
            var sum = 0;
            mqHost.RegisterHandler<Incr>(c =>
            {
                var dto = c.GetBody();
                sum += dto.Value;
                log.InfoFormat("Received {0}, sum: {1}", dto.Value, sum);
                msgsProcessed++;
                return null;
            });

            mqHost.Start();

            10.Times(i =>
            {
                ThreadPool.QueueUserWorkItem(x =>
                {
                    using (var client = mqHost.CreateMessageQueueClient())
                    {
                        try
                        {
                            log.InfoFormat("Publish: {0}...", i);
                            client.Publish(new Incr { Value = i });
                        }
                        catch (Exception ex)
                        {
                            log.InfoFormat("Start Publish exception: {0}", ex.Message);
                            clientManager.GetClientPoolActiveStates().PrintDump();
                            clientManager.GetReadOnlyClientPoolActiveStates().PrintDump();
                        }
                        Thread.Sleep(10);
                    }
                });
            });

            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var client = (RedisClient)clientManager.GetClient())
                {
                    client.SetConfig("timeout", "1");
                    var clientAddrs = client.GetClientList().ConvertAll(x => x["addr"]);
                    log.InfoFormat("Killing clients: {0}...", clientAddrs.Dump());

                    try
                    {
                        clientAddrs.ForEach(client.ClientKill);
                    }
                    catch (Exception ex)
                    {
                        log.InfoFormat("Client exception: {0}", ex.Message);
                    }
                }
            });

            20.Times(i =>
            {
                using (var client = mqHost.CreateMessageQueueClient())
                {
                    try
                    {
                        log.InfoFormat("Publish: {0}...", i);
                        client.Publish(new Incr { Value = i });
                    }
                    catch (Exception ex)
                    {
                        log.InfoFormat("Publish exception: {0}", ex.Message);
                        clientManager.GetClientPoolActiveStates().PrintDump();
                        clientManager.GetReadOnlyClientPoolActiveStates().PrintDump();
                    }
                }

                Thread.Sleep(1000);
            });

            Thread.Sleep(2000);
            "Messages processed: {0}".Print(msgsProcessed);
            "Logs: ".Print();
            sbLogFactory.GetLogs().Print();
            Console.ReadKey();
        }
開發者ID:modulexcite,項目名稱:ServiceStack.Redis,代碼行數:93,代碼來源:Program.cs


注:本文中的ServiceStack.Redis.PooledRedisClientManager.GetReadOnlyClientPoolActiveStates方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。