如何使用 ServiceStack 客户端管理器正确注册 Redis Master 和 Slaves?
How to properly register Redis Master and Slaves with ServiceStack Client Managers?
当我在 Google Compute Engine 上配置默认 Redis 集群时,有一个主服务器和 2 个只读从服务器,Redis Sentinel 在每台机器上 运行。考虑到之前的集群,我现在想在我的 ServiceStack 服务中使用它,但是 Sentinel 设置让我感到困惑,通常我会按照以下方式做一些事情:
container.Register<IRedisClientsManager>(c =>
new RedisManagerPool(container.Resolve<IAppSettings>().GetString("Redis:Master")));
var cacheClient = container.Resolve<IRedisClientsManager>().GetCacheClient();
container.Register(cacheClient);
所以这个设置有一些不完整的地方,我如何指定主站和 2 个只读从站,并配置 Sentinel?
ServiceStack.Redis is available in the RedisSentinel
class but as it's still being tested, it's not yet announced. You can find some info on how to use and configure a 中的 RedisSentinel 支持。
配置 RedisSentinel
使用 Redis Sentinel 时,管理单个 master/slave 连接的是 Redis sentinel 外部进程,因此您只需配置 sentinel 主机并忽略单个 master/slave 连接。
配置 RedisClientManager
或者,如果您使用 Redis Client Manager you would do the opposite, i.e. ignore the sentinels hosts and configure the Redis Client Managers with the master and slave hosts. Only the PooledRedisClientManager 支持配置 read-write/master 和 read-only/slave 主机,例如:
container.Register<IRedisClientsManager>(c =>
new PooledRedisClientManager(redisReadWriteHosts, redisReadOnlyHosts) {
ConnectTimeout = 100,
//...
});
当我在 Google Compute Engine 上配置默认 Redis 集群时,有一个主服务器和 2 个只读从服务器,Redis Sentinel 在每台机器上 运行。考虑到之前的集群,我现在想在我的 ServiceStack 服务中使用它,但是 Sentinel 设置让我感到困惑,通常我会按照以下方式做一些事情:
container.Register<IRedisClientsManager>(c =>
new RedisManagerPool(container.Resolve<IAppSettings>().GetString("Redis:Master")));
var cacheClient = container.Resolve<IRedisClientsManager>().GetCacheClient();
container.Register(cacheClient);
所以这个设置有一些不完整的地方,我如何指定主站和 2 个只读从站,并配置 Sentinel?
ServiceStack.Redis is available in the RedisSentinel
class but as it's still being tested, it's not yet announced. You can find some info on how to use and configure a
配置 RedisSentinel
使用 Redis Sentinel 时,管理单个 master/slave 连接的是 Redis sentinel 外部进程,因此您只需配置 sentinel 主机并忽略单个 master/slave 连接。
配置 RedisClientManager
或者,如果您使用 Redis Client Manager you would do the opposite, i.e. ignore the sentinels hosts and configure the Redis Client Managers with the master and slave hosts. Only the PooledRedisClientManager 支持配置 read-write/master 和 read-only/slave 主机,例如:
container.Register<IRedisClientsManager>(c =>
new PooledRedisClientManager(redisReadWriteHosts, redisReadOnlyHosts) {
ConnectTimeout = 100,
//...
});