本文整理匯總了C#中ServiceStack.Redis.PooledRedisClientManager.GetClientPoolActiveStates方法的典型用法代碼示例。如果您正苦於以下問題:C# PooledRedisClientManager.GetClientPoolActiveStates方法的具體用法?C# PooledRedisClientManager.GetClientPoolActiveStates怎麽用?C# PooledRedisClientManager.GetClientPoolActiveStates使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ServiceStack.Redis.PooledRedisClientManager
的用法示例。
在下文中一共展示了PooledRedisClientManager.GetClientPoolActiveStates方法的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();
}