Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

this command is not available unless the connection is created with admin-commands enabled

When trying to run the following in Redis using booksleeve.

using (var conn = new RedisConnection(server, port, -1, password))
{
    var result = conn.Server.FlushDb(0);
    result.Wait();
}

I get an error saying:

This command is not available unless the connection is created with admin-commands enabled"

I am not sure how do i execute commands as admin? Do I need to create an a/c in db with admin access and login with that?

like image 436
Justin Homes Avatar asked Aug 10 '13 18:08

Justin Homes


4 Answers

Updated answer for StackExchange.Redis:

var conn = ConnectionMultiplexer.Connect("localhost,allowAdmin=true");

Note also that the object created here should be created once per application and shared as a global singleton, per Marc:

Because the ConnectionMultiplexer does a lot, it is designed to be shared and reused between callers. You should not create a ConnectionMultiplexer per operation. It is fully thread-safe and ready for this usage.

like image 184
Todd Menier Avatar answered Nov 16 '22 20:11

Todd Menier


Basically, the dangerous commands that you don't need in routine operations, but which can cause lots of problems if used inappropriately (i.e. the equivalent of drop database in tsql, since your example is FlushDb) are protected by a "yes, I meant to do that..." flag:

using (var conn = new RedisConnection(server, port, -1, password,
          allowAdmin: true)) <==== here

I will improve the error message to make this very clear and explicit.

like image 23
Marc Gravell Avatar answered Nov 16 '22 19:11

Marc Gravell


You can also set this in C# when you're creating your multiplexer - set AllowAdmin = true

    private ConnectionMultiplexer GetConnectionMultiplexer()
    {
        var options = ConfigurationOptions.Parse("localhost:6379");
        options.ConnectRetry = 5;
        options.AllowAdmin = true;
        return ConnectionMultiplexer.Connect(options);
    }
like image 5
David McEleney Avatar answered Nov 16 '22 20:11

David McEleney


For those who like me faced the error:

StackExchange.Redis.RedisCommandException: This operation is not available unless admin mode is enabled: ROLE

after upgrading StackExchange.Redis to version 2.2.4 with Sentinel connection: it's a known bug, the workaround was either to downgrade the client back or to add allowAdmin=true to the connection string and wait for the fix.

Starting from 2.2.50 public release the issue is fixed.

like image 3
d_f Avatar answered Nov 16 '22 20:11

d_f