Skip to content
This repository has been archived by the owner on Jul 11, 2021. It is now read-only.

Commit

Permalink
redis-cli: stop showing incorrectly selected DB
Browse files Browse the repository at this point in the history
Previously redis-cli would happily show "-1" or "99999"
as valid DB choices.

Now, if the SELECT call returned an error, we don't update
the DB number in the CLI.

Inspired by @anupshendkar in redis#1313

Fixes redis#566, redis#1313
  • Loading branch information
mattsta committed Aug 1, 2014
1 parent bc1c8b8 commit 69ab545
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/redis-cli.c
Expand Up @@ -94,6 +94,7 @@ static struct config {
sds mb_delim;
char prompt[128];
char *eval;
int last_cmd_type;
} config;

static volatile sig_atomic_t force_cancel_loop = 0;
Expand Down Expand Up @@ -131,7 +132,7 @@ static void cliRefreshPrompt(void) {
strchr(config.hostip,':') ? "[%s]:%d" : "%s:%d",
config.hostip, config.hostport);
/* Add [dbnum] if needed */
if (config.dbnum != 0)
if (config.dbnum != 0 && config.last_cmd_type != REDIS_REPLY_ERROR)
len += snprintf(config.prompt+len,sizeof(config.prompt)-len,"[%d]",
config.dbnum);
snprintf(config.prompt+len,sizeof(config.prompt)-len,"> ");
Expand Down Expand Up @@ -532,6 +533,8 @@ static int cliReadReply(int output_raw_strings) {

reply = (redisReply*)_reply;

config.last_cmd_type = reply->type;

/* Check if we need to connect to a different node and reissue the
* request. */
if (config.cluster_mode && reply->type == REDIS_REPLY_ERROR &&
Expand Down Expand Up @@ -1887,6 +1890,8 @@ int main(int argc, char **argv) {
config.stdinarg = 0;
config.auth = NULL;
config.eval = NULL;
config.last_cmd_type = -1;

if (!isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL))
config.output = OUTPUT_RAW;
else
Expand Down

0 comments on commit 69ab545

Please sign in to comment.