创建连接池
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" });