Commit 28b54b5d authored by Matt Stancliff's avatar Matt Stancliff Committed by antirez
Browse files

redis-cli: Re-attach selected DB after auth

Previously, if you did SELECT then AUTH, redis-cli
would show your SELECT'd db even though it didn't
happen.

Note: running into this situation is a (hopefully) very limited
used case of people using multiple DBs and AUTH all at the same
time.

Fixes antirez#1639
parent ff58d5a3
...@@ -320,8 +320,10 @@ static int cliSelect() { ...@@ -320,8 +320,10 @@ static int cliSelect() {
reply = redisCommand(context,"SELECT %d",config.dbnum); reply = redisCommand(context,"SELECT %d",config.dbnum);
if (reply != NULL) { if (reply != NULL) {
int result = REDIS_OK;
if (reply->type == REDIS_REPLY_ERROR) result = REDIS_ERR;
freeReplyObject(reply); freeReplyObject(reply);
return REDIS_OK; return result;
} }
return REDIS_ERR; return REDIS_ERR;
} }
...@@ -649,6 +651,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) { ...@@ -649,6 +651,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
if (!strcasecmp(command,"select") && argc == 2) { if (!strcasecmp(command,"select") && argc == 2) {
config.dbnum = atoi(argv[1]); config.dbnum = atoi(argv[1]);
cliRefreshPrompt(); cliRefreshPrompt();
} else if (!strcasecmp(command,"auth") && argc == 2) {
cliSelect();
} }
} }
if (config.interval) usleep(config.interval); if (config.interval) usleep(config.interval);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment