From e3c0ea1cb4ca80c57184a8894586e8fc3c646da1 Mon Sep 17 00:00:00 2001 From: Binbin Date: Thu, 2 Dec 2021 16:41:50 +0800 Subject: [PATCH] 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> ``` --- src/redis-cli.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/redis-cli.c b/src/redis-cli.c index 060f3ef66..950e591f1 100644 --- a/src/redis-cli.c +++ b/src/redis-cli.c @@ -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;