使用 ServiceStack 连接到多个 Redis 实例

Connect to Multiple Redis Instance using ServiceStack

我的主机上有多个 redis 实例(端口 6379、6380)。目前我可以使用以下设置连接到第一个实例 (6379):

services.AddSingleton<IRedisClientsManager>(p =>
               new PooledRedisClientManager(Configuration.GetValue<long>("Redis:DatabaseId"), Configuration.GetValue<string>("127.0.0.1:6379"))
               {
                   ConnectTimeout = Configuration.GetValue<int>("Redis:connectTimeOut"),
                   IdleTimeOutSecs = Configuration.GetValue<int>("Redis:idleTimeOutSecs"),
                   PoolTimeout = Configuration.GetValue<int>("Redis:poolTimeOut")
               });

鉴于过去使用单个 Redis 实例或 Redis sentinel 的经验,我决定将互斥操作拆分到多个 Redis 实例以分散工作负载

例如:

所有操作 A 将使用 6379 实例,同时 所有操作B将使用6380实例

我已阅读 ServiceStack 文档,但未找到任何相关信息。

关于如何实现这一点有什么建议吗?

当您为 PooledRedisClientManager 配置主服务器和副本服务器时,当您解析 read/write 客户端时,即:

using var redis = clientsManager.GetClient();

它将解析连接到主服务器的客户端,而在解析只读客户端时:

using var redisReadOnly = clientsManager.GetReadOnlyClient();

它将改为解析连接到其中一个副本的客户端。