]> git.saurik.com Git - redis.git/commitdiff
It is now possible to use authentication and DB selection options at the same time...
authorantirez <antirez@gmail.com>
Mon, 30 Aug 2010 13:36:13 +0000 (15:36 +0200)
committerantirez <antirez@gmail.com>
Mon, 30 Aug 2010 13:36:13 +0000 (15:36 +0200)
src/redis-cli.c

index 3a6b0a9024ee583ea57b087d524095c16286dc5f..0b2fd0c1444d65e4278ebdab005dfa072b564e93 100644 (file)
@@ -478,10 +478,16 @@ int main(int argc, char **argv) {
 
     if (config.auth != NULL) {
         char *authargv[2];
+        int dbnum = config.dbnum;
 
+        /* We need to save the real configured database number and set it to
+         * zero here, otherwise cliSendCommand() will try to perform the
+         * SELECT command before the authentication, and it will fail. */
+        config.dbnum = 0;
         authargv[0] = "AUTH";
         authargv[1] = config.auth;
         cliSendCommand(2, convertToSds(2, authargv), 1);
+        config.dbnum = dbnum; /* restore the right DB number */
     }
 
     /* Start interactive mode when no command is provided */