mirror of
https://github.com/fluencelabs/redis
synced 2025-04-01 23:31:03 +00:00
redis-cli: stop showing incorrectly selected DB
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 #1313 Fixes #566, #1313
This commit is contained in:
parent
bbc1cd0bd9
commit
0042fb0eb0
@ -94,6 +94,7 @@ static struct config {
|
|||||||
sds mb_delim;
|
sds mb_delim;
|
||||||
char prompt[128];
|
char prompt[128];
|
||||||
char *eval;
|
char *eval;
|
||||||
|
int last_cmd_type;
|
||||||
} config;
|
} config;
|
||||||
|
|
||||||
static volatile sig_atomic_t force_cancel_loop = 0;
|
static volatile sig_atomic_t force_cancel_loop = 0;
|
||||||
@ -131,7 +132,7 @@ static void cliRefreshPrompt(void) {
|
|||||||
strchr(config.hostip,':') ? "[%s]:%d" : "%s:%d",
|
strchr(config.hostip,':') ? "[%s]:%d" : "%s:%d",
|
||||||
config.hostip, config.hostport);
|
config.hostip, config.hostport);
|
||||||
/* Add [dbnum] if needed */
|
/* 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]",
|
len += snprintf(config.prompt+len,sizeof(config.prompt)-len,"[%d]",
|
||||||
config.dbnum);
|
config.dbnum);
|
||||||
snprintf(config.prompt+len,sizeof(config.prompt)-len,"> ");
|
snprintf(config.prompt+len,sizeof(config.prompt)-len,"> ");
|
||||||
@ -532,6 +533,8 @@ static int cliReadReply(int output_raw_strings) {
|
|||||||
|
|
||||||
reply = (redisReply*)_reply;
|
reply = (redisReply*)_reply;
|
||||||
|
|
||||||
|
config.last_cmd_type = reply->type;
|
||||||
|
|
||||||
/* Check if we need to connect to a different node and reissue the
|
/* Check if we need to connect to a different node and reissue the
|
||||||
* request. */
|
* request. */
|
||||||
if (config.cluster_mode && reply->type == REDIS_REPLY_ERROR &&
|
if (config.cluster_mode && reply->type == REDIS_REPLY_ERROR &&
|
||||||
@ -1887,6 +1890,8 @@ int main(int argc, char **argv) {
|
|||||||
config.stdinarg = 0;
|
config.stdinarg = 0;
|
||||||
config.auth = NULL;
|
config.auth = NULL;
|
||||||
config.eval = NULL;
|
config.eval = NULL;
|
||||||
|
config.last_cmd_type = -1;
|
||||||
|
|
||||||
if (!isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL))
|
if (!isatty(fileno(stdout)) && (getenv("FAKETTY") == NULL))
|
||||||
config.output = OUTPUT_RAW;
|
config.output = OUTPUT_RAW;
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user