ServiceStack.Redis連接阿里云redis服務(wù)的問題
下面的C#代碼可以正常連接:
_cache = new RedisClient(_options.Host, _options.Port, _options.Password);
下面的C#代碼連接時(shí)
var host = $"{_options.Password}@{_options.Host}:{_options.Port}";var manager = new RedisManagerPool(host);var client = manager.GetClient();
報(bào)錯(cuò):
ServiceStack.Redis.RedisResponseException: command role not support for normal user
? at ServiceStack.Redis.RedisNativeClient.ReadComplexResponse() in /opt/lib/teamcity-agent/work/8dcfdcec54d0f21a/src/ServiceStack.Redis/RedisNativeClient_Utils.cs:line 1031
_options.Host 的值是?實(shí)例ID.redis.rds.aliyuncs.com?
_options.Password 的值是?實(shí)例ID:密碼?
問題發(fā)生在 ServiceStack.Redis 的 RedisResolver 中下面的代碼:
public virtual RedisClient CreateRedisClient(RedisEndpoint config, bool master)
{
? ? var client = ClientFactory(config);
? ? if (master && RedisConfig.VerifyMasterConnections)
? ? {
? ? ? ? var role = client.GetServerRole();
? ? ? ? //..? ? }
? ? return client;
}
而阿里云的 redis 服務(wù)目前不支持 redis 的 role 命令坐梯。
解決方法是將?RedisConfig.VerifyMasterConnections 的值設(shè)置為 false 棚品。
RedisConfig.VerifyMasterConnections = false;
其他回答(3)
RedisConfig.VerifyMasterConnections = false;
// 支持讀寫分離,均衡負(fù)載?
return new PooledRedisClientManager(readWriteHosts, readOnlyHosts, new RedisClientManagerConfig
{
MaxWritePoolSize = 20, // “寫”鏈接池鏈接數(shù)?
MaxReadPoolSize = 50, // “讀”鏈接池鏈接數(shù)?
AutoStart = true,
});
入坑。
這樣改了,對(duì)于Redis是使用集群還是主備有影響嗎融撞?我使用的是PooledRedisClientManager鏈接Redis(ServiceStack.Redis.4.0.62)
問題解決计雌,多謝
*本文參考https://q.cnblogs.com/q/89946/荣赶,僅用于學(xué)習(xí)昧谊。