Skip to content

Sentinel ConnectionMultiplexer throw RedisCommandException #1630

Closed

Description

@thangnn91

My source code perfectly worked at version 2.1.28. Then, I was updating target framework to net5.0, also upgraded StackExchange Redis
to newest version, and I got the exception
I tried downgrading Nuget version 2.2.3, 2.1.58, but still got the error. I think a certain version after 2.1.28 has been changed
My ConnectionMultiplexer source:

ConfigurationOptions sentinelConfig = new ConfigurationOptions(); sentinelConfig.ServiceName = redisSection.ServiceName;

           foreach (var item in redisSection.Sentinels)
            {
                sentinelConfig.EndPoints.Add(System.Net.IPAddress.Parse(item.Host), item.Port);
            }
            if (!string.IsNullOrEmpty(redisSection.SetinelPassword))
            {
                sentinelConfig.Password = redisSection.SetinelPassword;
                sentinelConfig.CommandMap = CommandMap.Create(new HashSet<string>
                { 
                    // custom cmd
                    "INFO","PING","AUTH","PSUBSCRIBE","PUNSUBSCRIBE","SENTINEL","SHUTDOWN","SUBSCRIBE","UNSUBSCRIBE", "ROLE"
                });
            }
            else
                sentinelConfig.CommandMap = CommandMap.Sentinel;
            sentinelConfig.TieBreaker = "";
            //sentinelConfig.DefaultVersion = new Version(4, 0, 11);
            // its important to set the Sentinel commands supported


            // Get sentinel connection
            ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.Connect(sentinelConfig, Console.Out);
            // Create master service configuration
            ConfigurationOptions masterConfig = new ConfigurationOptions
            {
                ServiceName = redisSection.ServiceName,
                EndPoints = { { redisSection.Host, redisSection.Port } },
                DefaultDatabase = redisSection.Database
            };
            if (!string.IsNullOrEmpty(redisSection.Password)) masterConfig.Password = redisSection.Password;
            //// Get master Redis connection
            //var redisMasterConnection = sentinelConnection.GetSentinelMasterConnection(masterConfig);
            Connection = new Lazy<ConnectionMultiplexer>(() => sentinelConnection.GetSentinelMasterConnection(masterConfig));`

Exception I got:
StackExchange.Redis.RedisCommandException: This operation is not available unless admin mode is enabled: ROLE
I tried adding
sentinelConfig.AllowAdmin=true
Then I got other exception:
This operation has been disabled in the command-map and cannot be used: ROLE

Activity

  1. mgravell commented on Dec 3, 2020

    @mgravell
    Member

    agree it shouldn't need AllowAdmin - that's fixed (commit above); I think the problem otherwise is that by specifying a ServiceName (which historically did nothing), it now tries to connect through the sentinel to the actual redis server, which isn't what you're expecting - and it is borking the command-map in the process.

    If you explicitly want to connect to sentinel: SentinelConnect may be what you want. If you're trying to connect via sentinel, then SentinelMasterConnect ?

  2. thangnn91 commented on Dec 3, 2020

    @thangnn91
    Author

    agree it shouldn't need AllowAdmin - that's fixed (commit above); I think the problem otherwise is that by specifying a ServiceName (which historically did nothing), it now tries to connect through the sentinel to the actual redis server, which isn't what you're expecting - and it is borking the command-map in the process.

    If you explicitly want to connect to sentinel: SentinelConnect may be what you want. If you're trying to connect via sentinel, then SentinelMasterConnect ?

    Thanks for replying, maybe my source code was used to connect to sentinel is in old nuget version
    I have just changed:
    ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.SentinelConnect(sentinelConfig, Console.Out);
    also I configured
    sentinelConfig.AllowAdmin = true; masterConfig.AllowAdmin = true;
    and my project work fine

  3. NickCraver commented on May 20, 2021

    @NickCraver
    Collaborator

    Glad you're all going! Closing out since the ROLE issue was fixed in 6409b9d

  4. added a commit that references this issue on Jun 7, 2024
    6409b9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions