Skip to content

Commit

Permalink
redis-cli: Re-attach selected DB after auth
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mattsta committed Aug 1, 2014
1 parent 1782d04 commit a1b42b3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/redis-cli.c
Expand Up @@ -320,8 +320,10 @@ static int cliSelect() {

reply = redisCommand(context,"SELECT %d",config.dbnum);
if (reply != NULL) {
int result = REDIS_OK;
if (reply->type == REDIS_REPLY_ERROR) result = REDIS_ERR;
freeReplyObject(reply);
return REDIS_OK;
return result;
}
return REDIS_ERR;
}
Expand Down Expand Up @@ -650,6 +652,8 @@ static int cliSendCommand(int argc, char **argv, int repeat) {
if (!strcasecmp(command,"select") && argc == 2) {
config.dbnum = atoi(argv[1]);
cliRefreshPrompt();
} else if (!strcasecmp(command,"auth") && argc == 2) {
cliSelect();
}
}
if (config.interval) usleep(config.interval);
Expand Down

0 comments on commit a1b42b3

Please sign in to comment.