public void RedisManagerPool_can_execute_CustomResolver() { var resolver = new FixedResolver(MasterHosts[0].ToRedisEndpoint(), SlaveHosts[0].ToRedisEndpoint()); using (var redisManager = new RedisManagerPool("127.0.0.1:8888") { RedisResolver = resolver }) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.SetValue("KEY", "1"); } using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); master.Increment("KEY", 1); } Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1)); 5.Times(i => { using (var slave = redisManager.GetReadOnlyClient()) { Assert.That(slave.GetHostString(), Is.EqualTo(MasterHosts[0])); Assert.That(slave.GetValue("KEY"), Is.EqualTo("2")); } }); Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1)); redisManager.FailoverTo("127.0.0.1:9999", "127.0.0.1:9999"); 5.Times(i => { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(MasterHosts[0])); Assert.That(master.GetValue("KEY"), Is.EqualTo("2")); } using (var slave = redisManager.GetReadOnlyClient()) { Assert.That(slave.GetHostString(), Is.EqualTo(MasterHosts[0])); Assert.That(slave.GetValue("KEY"), Is.EqualTo("2")); } }); Assert.That(resolver.NewClientsInitialized, Is.EqualTo(2)); } }
public void RedisManagerPool_can_execute_CustomResolver() { var resolver = new FixedResolver(RedisEndpoint.Create(Config.Sentinel6380), RedisEndpoint.Create(Config.Sentinel6381)); using (var redisManager = new RedisManagerPool("127.0.0.1:8888") { RedisResolver = resolver }) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380)); master.SetValue("KEY", "1"); } using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380)); master.Increment("KEY", 1); } Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1)); for (var i = 0; i < 5; i++) { using (var slave = redisManager.GetReadOnlyClient()) { Assert.That(slave.GetHostString(), Is.EqualTo(Config.Sentinel6380)); Assert.That(slave.GetValue("KEY"), Is.EqualTo("2")); } } Assert.That(resolver.NewClientsInitialized, Is.EqualTo(1)); redisManager.FailoverTo("127.0.0.1:9999", "127.0.0.1:9999"); for (var i = 0; i < 5; i++) { using (var master = redisManager.GetClient()) { Assert.That(master.GetHostString(), Is.EqualTo(Config.Sentinel6380)); Assert.That(master.GetValue("KEY"), Is.EqualTo("2")); } using (var slave = redisManager.GetReadOnlyClient()) { Assert.That(slave.GetHostString(), Is.EqualTo(Config.Sentinel6380)); Assert.That(slave.GetValue("KEY"), Is.EqualTo("2")); } } Assert.That(resolver.NewClientsInitialized, Is.EqualTo(2)); } }