Fix a harmless bug when using monitor in redis-cli with wrong reply (#9875)

When we use monitor in redis-cli but encounter an error reply,
we will get stuck until we press Ctrl-C to quit.

This is a harmless bug. It might be useful if we add parameters
to monitor in the future, suck as monitoring only selected db.

before:
```
127.0.0.1:6379> monitor wrong
(error) ERR wrong number of arguments for 'monitor' command or subcommand
^C(9.98s)
127.0.0.1:6379>
```

after:
```
127.0.0.1:6379> monitor wrong
(error) ERR wrong number of arguments for 'monitor' command or subcommand
127.0.0.1:6379>
```
This commit is contained in:
Binbin 2021-12-02 16:41:50 +08:00 committed by GitHub
parent 0e5b813ef9
commit e3c0ea1cb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 0 deletions

View File

@ -1347,6 +1347,10 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
do {
if (cliReadReply(output_raw) != REDIS_OK) exit(1);
fflush(stdout);
/* This happens when the MONITOR command returns an error. */
if (config.last_cmd_type == REDIS_REPLY_ERROR)
config.monitor_mode = 0;
} while(config.monitor_mode);
zfree(argvlen);
return REDIS_OK;