ServiceStack.Redis连接阿里云redis服务时使用连接池出现的问题

2023-06-12,,

创建连接池

      private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip:port" }, new string[] { "password@ip:port" });
public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts)
{
//支持读写分离,均衡负载
return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
{
MaxWritePoolSize = ,//“写”链接池链接数
MaxReadPoolSize = ,//“读”链接池链接数
AutoStart = true,
DefaultDb =
});
}

调用

using (IRedisClient Redis = prcm.GetClient()) {
Redis.Set(key, value, dateTime);
}

这是会出现错误  command role not support for your account

解决方案:

在创建连接池的时候 加入这样一句代码  RedisConfig.VerifyMasterConnections = false;

 public static PooledRedisClientManager CreateManager(string[] readWriteHosts, string[] readOnlyHosts)
{
RedisConfig.VerifyMasterConnections = false;
//支持读写分离,均衡负载
return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
{
MaxWritePoolSize = ,//“写”链接池链接数
MaxReadPoolSize = ,//“读”链接池链接数
AutoStart = true,
DefaultDb =
});
}

问题解决!

另外一个错误

NOAUTH Authentication required

解决方法

private static PooledRedisClientManager prcm = CreateManager(new string[] { "password@ip:port" }, new string[] { "password@ip:port" });

ServiceStack.Redis连接阿里云redis服务时使用连接池出现的问题的相关教程结束。

《ServiceStack.Redis连接阿里云redis服务时使用连接池出现的问题.doc》

下载本文的Word格式文档,以方便收藏与打印。