How does ServiceStack PooledRedisClientManager fai

2019-03-20 12:02发布

问题:

According to the git commit messages, ServiceStack has recently added failover support. I initially assumed this meant that I could pull one of my Redis instances down, and my pooled client manager would handle the failover elegantly and try to connect with one of my alternate Redis instances. Unfortunately, my code just bugs out and says that it can't connect with the initial Redis instance.

I am currently running instances of Redis 2.6.12 on a Windows, with the master at port 6379 and a slave at 6380, with sentinels set up to automatically promote the slave to a master if the master goes down. I am currently instantiating my client manager like this:

PooledRedisClientManager pooledClientManager =
    new PooledRedisClientManager(new string[1] { "localhost:6379"},
        new string[1] {"localhost:6380"});

where the first array is read-write hosts (for the master), and the second array is read-only hosts (for the slave).

When I terminate the master at port 6379, the sentinels promote the slave to a master. Now, when I try to run my C# code, instead of failing over to port 6380, it simply breaks and returns the error "could not connect to redis Instance at localhost:6379".

Is there a way around this, or will failover simply not work the way I want it to?

回答1:

PooledRedisClientManager.FailoverTo allows you to reset which are the read/write hosts, vs readonly hosts, and restart the factory. This allows for a quick transition without needing to recreate clients.