Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{"This operation has been disabled in the command-map and cannot be used: SET"} #1580

Closed
jeremiahedge opened this issue Oct 8, 2020 · 13 comments

Comments

@jeremiahedge
Copy link

jeremiahedge commented Oct 8, 2020

I keep running into an issue when i use sentinelconnect, i get all the commandmaps added without me doing it. I've use the latest from the myget stackoverflow package

my code

ConfigurationOptions sentinelConfig = new ConfigurationOptions();

            sentinelConfig.EndPoints.Add("localhost", 26379);
            sentinelConfig.TieBreaker = "";
            sentinelConfig.AbortOnConnectFail = false;
            // its important to set the Sentinel commands supported

            ConnectionMultiplexer redis = ConnectionMultiplexer.SentinelConnect(sentinelConfig, Console.Out);
IDatabase db = redis.GetDatabase();
            
                
                db.StringSet("key", "value");

First output in the console is this: localhost:26379,abortConnect=False,$NONE=,$APPEND=,$ASKING=,$BGREWRITEAOF=,$BGSAVE=,$BITCOUNT=,$BITOP=,$BITPOS=,$BLPOP=,$BRPOP=,$BRPOPLPUSH=,$CLIENT=,$CLUSTER=,$CONFIG=,$DBSIZE=,$DEBUG=,$DECR=,$DECRBY=,$DEL=,$DISCARD=,$DUMP=,$ECHO=,$EVAL=,$EVALSHA=,$EXEC=,$EXISTS=,$EXPIRE=,$EXPIREAT=,$FLUSHALL=,$FLUSHDB=,$GEOADD=,$GEODIST=,$GEOHASH=,$GEOPOS=,$GEORADIUS=,$GEORADIUSBYMEMBER=,$GET=,$GETBIT=,$GETRANGE=,$GETSET=,$HDEL=,$HEXISTS=,$HGET=,$HGETALL=,$HINCRBY=,$HINCRBYFLOAT=,$HKEYS=,$HLEN=,$HMGET=,$HMSET=,$HSCAN=,$HSET=,$HSETNX=,$HSTRLEN=,$HVALS=,$INCR=,$INCRBY=,$INCRBYFLOAT=,$KEYS=,$LASTSAVE=,$LATENCY=,$LINDEX=,$LINSERT=,$LLEN=,$LPOP=,$LPUSH=,$LPUSHX=,$LRANGE=,$LREM=,$LSET=,$LTRIM=,$MEMORY=,$MGET=,$MIGRATE=,$MONITOR=,$MOVE=,$MSET=,$MSETNX=,$MULTI=,$OBJECT=,$PERSIST=,$PEXPIRE=,$PEXPIREAT=,$PFADD=,$PFCOUNT=,$PFMERGE=,$PSETEX=,$PTTL=,$PUBLISH=,$PUBSUB=,$QUIT=,$RANDOMKEY=,$READONLY=,$READWRITE=,$RENAME=,$RENAMENX=,$REPLICAOF=,$RESTORE=,$RPOP=,$RPOPLPUSH=,$RPUSH=,$RPUSHX=,$SADD=,$SAVE=,$SCAN=,$SCARD=,$SCRIPT=,$SDIFF=,$SDIFFSTORE=,$SELECT=,$SET=,$SETBIT=,$SETEX=,$SETNX=,$SETRANGE=,$SINTER=,$SINTERSTORE=,$SISMEMBER=,$SLAVEOF=,$SLOWLOG=,$SMEMBERS=,$SMOVE=,$SORT=,$SPOP=,$SRANDMEMBER=,$SREM=,$STRLEN=,$SUNION=,$SUNIONSTORE=,$SSCAN=,$SWAPDB=,$SYNC=,$TIME=,$TOUCH=,$TTL=,$TYPE=,$UNLINK=,$UNWATCH=,$WATCH=,$XACK=,$XADD=,$XCLAIM=,$XDEL=,$XGROUP=,$XINFO=,$XLEN=,$XPENDING=,$XRANGE=,$XREAD=,$XREADGROUP=,$XREVRANGE=,$XTRIM=,$ZADD=,$ZCARD=,$ZCOUNT=,$ZINCRBY=,$ZINTERSTORE=,$ZLEXCOUNT=,$ZPOPMAX=,$ZPOPMIN=,$ZRANGE=,$ZRANGEBYLEX=,$ZRANGEBYSCORE=,$ZRANK=,$ZREM=,$ZREMRANGEBYLEX=,$ZREMRANGEBYRANK=,$ZREMRANGEBYSCORE=,$ZREVRANGE=,$ZREVRANGEBYLEX=,$ZREVRANGEBYSCORE=,$ZREVRANK=,$ZSCAN=,$ZSCORE=,$ZUNIONSTORE=,$UNKNOWN=

As you can see, I'm not adding a map, however sentinelconnect adds all of these to the connection string.

I've also tried this

ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.SentinelConnect(sentinelConfig);
            // Create master service configuration
            ConfigurationOptions masterConfig = new ConfigurationOptions { ServiceName = "mymaster" };
            // Get master Redis connection
            var redisMasterConnection = sentinelConnection.GetSentinelMasterConnection(masterConfig);
            Console.WriteLine("trying db set");
            IDatabase db = redisMasterConnection.GetDatabase();
            db.StringSet("key", "value");

and the error i get is the connection is not a sentinel connection when the line with "GetSentinelMasterConnection" runs

Please help

@mgravell
Copy link
Collaborator

mgravell commented Oct 8, 2020 via email

@jeremiahedge
Copy link
Author

jeremiahedge commented Oct 8, 2020

Thanks for the response! I actually left a line out, I did have the service name


            ConfigurationOptions sentinelConfig = new ConfigurationOptions();
            sentinelConfig.ServiceName = "mymaster";
            sentinelConfig.EndPoints.Add("rfs-redis", 26379);
            sentinelConfig.TieBreaker = "";
            // its important to set the Sentinel commands supported

            // Get sentinel connection
            ConnectionMultiplexer sentinelConnection = ConnectionMultiplexer.SentinelConnect(sentinelConfig, Console.Out);
            // Create master service configuration
            ConfigurationOptions masterConfig = new ConfigurationOptions { ServiceName = "mymaster",CommandMap=CommandMap.Default};
            // Get master Redis connection
            Console.WriteLine("GETMASTER");
            var redisMasterConnection = sentinelConnection.GetSentinelMasterConnection(masterConfig,Console.Out);
        

This wouldn't work until i added CommandMap = CommandMap.Default to

            ConfigurationOptions masterConfig = new ConfigurationOptions { ServiceName = "mymaster",CommandMap=CommandMap.Default};


@NickCraver
Copy link
Collaborator

I'm not sure of the intent here - if you connect to the sentinel normally, we'll connect down to the master, are you wanting to do something with knowledge of the master underneath? Or do you just want to connect to whatever the master is and switch when Sentinel says to? If it's the latter, that's built-in and much simpler :)

@Victor-Tseng
Copy link

Instead of building the config object and call the SentinelConnect and GetSentinelMasterConnection, we are using the following way to connect to the master. And when master changed the connection can swing to new master accordingly.

ConnectionMultiplexer redis = ConnectionMultiplexer.Connect("172.17.6.45:26379,172.17.6.46:26379,172.17.6.47:26379,serviceName=mymaster");
IDatabase db = redis.GetDatabase(0);

@NickCraver
Copy link
Collaborator

I think we may be talking past each other. In a current version of the client, you need only connect to the Sentinel instance (any of them) and provide a service name on the connection string. The client already handles connecting to the master and switching when it changes. If you're doing this manually: alrighty, and good luck, but there's no need - it's built-in now.

@qjoseph
Copy link

qjoseph commented Nov 26, 2020

@NickCraver, the problem is that some libraries like StackExchange.Redis.Extensions use the signature with ConfigurationOption parameter instead of connection string parameter and so there is a problem when try to retrieve the MasterConnection with CommandMap.Sentinel configured.

Possible workaround :

private static async Task<ConnectionMultiplexer> SentinelMasterConnectAsync(ConfigurationOptions configuration, TextWriter log = null)
{
    var sentinelConnection = await SentinelConnectAsync(configuration, log).ForAwait();

    // This line fix the problem
    configuration.CommandMap = CommandMap.Default;

    var muxer = sentinelConnection.GetSentinelMasterConnection(configuration, log);
    // set reference to sentinel connection so that we can dispose it
    muxer.sentinelConnection = sentinelConnection;

    return muxer;
}

@mgravell
Copy link
Collaborator

mgravell commented Nov 26, 2020 via email

@gitkv
Copy link

gitkv commented Mar 11, 2021

@qjoseph I have the same problem.
Did you manage to solve this?

@NickCraver
Copy link
Collaborator

As Marc said here - we'd need an example here. The bug report here is basically "another library you don't control does something I don't expect" - okay, understood, but that's not something we're going to spend a half day chasing down. If anyone can provide a repro, we'd be happy to take a look. The time investment is high otherwise (you ma be familiar with this library, and it may be quick to reproduce...but we are not, and we don't have your setup, so chasing down the scenario based on limited into is a large and possibly fruitless time sink).

I don't know how this library is connecting in code or what configuration they're doing on the way in. It seems like the command map is off but it's unclear how, or even exactly what you're trying to do here (e.g. which connection we're after).

@rdeusser
Copy link

rdeusser commented Jul 15, 2021

@jeremiahedge Did you ever solve this? I've got the same problem. Exception gets thrown: StackExchange.Redis.RedisCommandException: This operation has been disabled in the command-map and cannot be used: SET and this is what my code looks like:

var configurationOptions = new ConfigurationOptions
{
    AllowAdmin = false,
    AbortOnConnectFail = false,
    ServiceName = "mymaster",
    EndPoints =
    {
	options.Value.RedisConnectionString,
    },
};

_conn = ConnectionMultiplexer.SentinelConnect(configurationOptions, Console.Out);
_db = _conn.GetDatabase(0);

At this point I expect to be able to use _db.StringSet without issue since SET is present in the command map.

@rdeusser
Copy link

Never mind. I figured it out. This is what I ended up doing:

var sentinelConfig = new ConfigurationOptions
    {
	AllowAdmin = false,
	AbortOnConnectFail = false,
	CommandMap = CommandMap.Sentinel,
	EndPoints =
	{
	    options.Value.RedisConnectionString,
	},
    };

    var masterConfig = new ConfigurationOptions
    {
	CommandMap = CommandMap.Default,
	ServiceName = "mymaster",
    };

    var sentinel = ConnectionMultiplexer.SentinelConnect(sentinelConfig, Console.Out);

    _conn = sentinel.GetSentinelMasterConnection(masterConfig, Console.Out);
    _db = _conn.GetDatabase(0);

@NickCraver
Copy link
Collaborator

It looks like there's a workaround above. If there's another library we can advise on how to better use us/configure the command map, I'm still happy to help but cannot do more without more info here. Let us know if there's more to go on!

@gitkv
Copy link

gitkv commented Feb 4, 2022

Это все еще не работает!
Что сложного исправить данный баг?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants