Unverified Commit e3c0ea1c authored by Binbin's avatar Binbin Committed by GitHub
Browse files

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>
```
parent 0e5b813e
...@@ -1347,6 +1347,10 @@ static int cliSendCommand(int argc, char **argv, long repeat) { ...@@ -1347,6 +1347,10 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
do { do {
if (cliReadReply(output_raw) != REDIS_OK) exit(1); if (cliReadReply(output_raw) != REDIS_OK) exit(1);
fflush(stdout); 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); } while(config.monitor_mode);
zfree(argvlen); zfree(argvlen);
return REDIS_OK; return REDIS_OK;
......
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