此操作已在命令Map中禁用,无法使用:auth:rediscommandexception

w46czmvw  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(456)

我有下面的代码来设置sentinel redis连接。

var redisConfiguration = configuration.GetSection(redisSettingsJsonSection).Get<EightRedisConfiguration>();

    var configOptions = new ConfigurationOptions
            {
                ServiceName = redisConfiguration.ServiceName,
                TieBreaker = string.Empty,
                DefaultVersion = new Version(
                    redisConfiguration.DefaultVersionMajor,
                    redisConfiguration.DefaultVersionMinor,
                    redisConfiguration.DefaultVersionBuild),
                Password = redisConfiguration.Password,
                AbortOnConnectFail = redisConfiguration.AbortOnConnectFail,
                Ssl = redisConfiguration.Ssl,
                AllowAdmin = redisConfiguration.AllowAdmin,
                ConnectTimeout = redisConfiguration.ConnectTimeout,
                DefaultDatabase = redisConfiguration.Database
            };

            foreach (var redisHost in redisConfiguration.Hosts)
            {
                configOptions.EndPoints.Add(redisHost.Host, redisHost.Port);
            }

            configOptions.CommandMap = redisConfiguration.IsSentinelCluster ? CommandMap.Sentinel : CommandMap.Default;

            services.AddSingleton(_ =>
                    ConnectionMultiplexer
                        .Connect(configOptions, logTextWriter)
                        .GetSentinelMasterConnection(configOptions));

我收到以下例外情况。

at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
   at System.Activator.CreateInstance(Type type)
This operation has been disabled in the command-map and cannot be used: AUTH: RedisCommandException
   at StackExchange.Redis.CommandMap.AssertAvailable(RedisCommand command) in /_/src/StackExchange.Redis/CommandMap.cs:line 169
   at StackExchange.Redis.ConnectionMultiplexer..ctor(ConfigurationOptions configuration) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1141
   at StackExchange.Redis.ConnectionMultiplexer.CreateMultiplexer(Object configuration, LogProxy log, EventHandler`1& connectHandler) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 958
   at StackExchange.Redis.ConnectionMultiplexer.ConnectImpl(Object configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1014
   at StackExchange.Redis.ConnectionMultiplexer.Connect(ConfigurationOptions configuration, TextWriter log) in /_/src/StackExchange.Redis/ConnectionMultiplexer.cs:line 1002

配置如下。

"DefaultVersionMajor": 4,
    "DefaultVersionMinor": 0,
    "DefaultVersionBuild": 11,
    "ServiceName": "eight-sentinel",
    "IsSentinelCluster": true,
    "Password": "AWESOME_PASSWORD",
    "AllowAdmin": true,
    "Ssl": false,
    "ConnectTimeout": 3000,
    "ConnectRetry": 2,
    "Database": 0,
    "Hosts": [
      {
        "Host": "redis-1.com",
        "Port": 26379
      },
      {
        "Host": "redis-2.com",
        "Port": 26379
      },
      {
        "Host": "redis-3.com",
        "Port": 26379
      }
    ]

我对这个问题有点迷茫,也不确定它背后的信息,我可以使用redis桌面管理器客户端连接到sentinel集群,只需添加第一个示例。

fykwrbwg

fykwrbwg1#

我也有一个类似的问题,经过一些研究,我意识到他们在图书馆有一些问题,似乎有一个问题与使用 ConfigurationOptions .
正如这里所建议的,如果您改为通过连接字符串创建连接,那么它是有效的

using(var connection=new ConnectionMultiplexer.Connect("10.1.3.11:26379,10.1.3.12:26379,10.1.3.13:26379,serviceName=redis-primary,AllowAdmin=true"))
{
// do stuff
}

您必须指定 ServiceName 以连接到sentinel。
他们引进了一种新方法 SentinelConnect 这不适用于同一个连接字符串!
如果您正在使用 StackExchange.Redis.Extensions.Core 如果库没有具有连接字符串的构造函数,则应创建redisconfiguration的空示例,并在connectionpoolmanager实现中通过connectionstring连接。

相关问题