本文整理汇总了C#中ServiceStack.Redis.PooledRedisClientManager.FailoverTo方法的典型用法代码示例。如果您正苦于以下问题:C# PooledRedisClientManager.FailoverTo方法的具体用法?C# PooledRedisClientManager.FailoverTo怎么用?C# PooledRedisClientManager.FailoverTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceStack.Redis.PooledRedisClientManager
的用法示例。
在下文中一共展示了PooledRedisClientManager.FailoverTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Can_failover_MqServer_at_runtime
public void Can_failover_MqServer_at_runtime()
{
const int iterations = 100;
var failoverHost = "redis-failover:6379";
var localClient = new RedisClient("localhost:6379");
localClient.FlushDb();
var failoverClient = new RedisClient(failoverHost);
failoverClient.FlushDb();
var clientManager = new PooledRedisClientManager(new[] { "localhost" });
var mqHost = new RedisMqServer(clientManager);
var map = new Dictionary<string, int>();
var received = 0;
mqHost.RegisterHandler<Msg>(c =>
{
var dto = c.GetBody();
received++;
int count;
map.TryGetValue(dto.Host, out count);
map[dto.Host] = count + 1;
lock (clientManager)
{
"Received #{0} from {1}".Print(received, dto.Host);
if (received == iterations)
Monitor.Pulse(clientManager);
}
return null;
});
mqHost.Start();
RunMqInLoop(mqHost, iterations: iterations, callback: () =>
{
lock (clientManager)
"{0} msgs were published.".Print(iterations);
});
Thread.Sleep(500);
clientManager.FailoverTo(failoverHost);
lock (clientManager)
Monitor.Wait(clientManager);
"localclient inq: {0}, outq: {1}".Print(
localClient.GetListCount("mq:Msg.inq"),
localClient.GetListCount("mq:Msg.outq"));
"failoverClient inq: {0}, outq: {1}".Print(
failoverClient.GetListCount("mq:Msg.inq"),
failoverClient.GetListCount("mq:Msg.outq"));
Assert.That(received, Is.EqualTo(100));
Assert.That(map.Count, Is.EqualTo(2));
var msgsFromAllHosts = 0;
foreach (var count in map.Values)
{
Assert.That(count, Is.GreaterThan(0));
msgsFromAllHosts += count;
}
Assert.That(msgsFromAllHosts, Is.EqualTo(iterations));
}
示例2: Can_failover_at_runtime
public void Can_failover_at_runtime()
{
var failoverHost = "redis-failover:6379";
string key = "test:failover";
var localClient = new RedisClient("localhost");
localClient.Remove(key);
var failoverClient = new RedisClient(failoverHost);
failoverClient.Remove(key);
var clientManager = new PooledRedisClientManager(new[] { "localhost" });
RunInLoop(clientManager, callback:() =>
{
lock (clientManager)
Monitor.Pulse(clientManager);
});
Thread.Sleep(100);
clientManager.FailoverTo(failoverHost);
lock (clientManager)
Monitor.Wait(clientManager);
var localIncr = localClient.Get<int>(key);
var failoverIncr = failoverClient.Get<int>(key);
Assert.That(localIncr, Is.GreaterThan(0));
Assert.That(failoverIncr, Is.GreaterThan(0));
Assert.That(localIncr + failoverIncr, Is.EqualTo(100));
}