From 7ea55bc16e4787a28ce80c6c27073a59c120eef4 Mon Sep 17 00:00:00 2001 From: xbasel <103044017+xbasel@users.noreply.github.com> Date: Tue, 25 Feb 2025 23:25:37 +0200 Subject: [PATCH 1/5] valkey-cli: ensure output ends with a newline if missing when printing reply Example: 127.0.0.1:6379> multi OK 127.0.0.1:6379(TX)> client info QUEUED127.0.0.1:6379(TX)> Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com> --- src/valkey-cli.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/valkey-cli.c b/src/valkey-cli.c index 0175684ab4..043aa69108 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -1989,6 +1989,10 @@ static sds cliFormatReplyRaw(redisReply *r) { break; default: fprintf(stderr, "Unknown reply type: %d\n", r->type); exit(1); } + /* Append newline only if the last character isn't already '\n' */ + if (sdslen(out) > 0 && out[sdslen(out) - 1] != '\n') { + out = sdscatlen(out, "\n", 1); + } return out; } From dc12b53b523b6a54491d5d651ca2f93d5fb24382 Mon Sep 17 00:00:00 2001 From: xbasel <103044017+xbasel@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:09:58 +0200 Subject: [PATCH 2/5] Don't use raw output if it multi-exec context Signed-off-by: xbasel <103044017+xbasel@users.noreply.github.com> --- src/valkey-cli.c | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/valkey-cli.c b/src/valkey-cli.c index 043aa69108..b8c10d8bd8 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -1989,10 +1989,6 @@ static sds cliFormatReplyRaw(redisReply *r) { break; default: fprintf(stderr, "Unknown reply type: %d\n", r->type); exit(1); } - /* Append newline only if the last character isn't already '\n' */ - if (sdslen(out) > 0 && out[sdslen(out) - 1] != '\n') { - out = sdscatlen(out, "\n", 1); - } return out; } @@ -2342,21 +2338,22 @@ static int cliSendCommand(int argc, char **argv, long repeat) { if (context == NULL) return REDIS_ERR; output_raw = 0; - if (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || - (argc >= 2 && !strcasecmp(command, "memory") && - (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || - (argc == 2 && !strcasecmp(command, "cluster") && - (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || - (argc >= 2 && !strcasecmp(command, "client") && - (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || - (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || - (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || - /* Format PROXY INFO command for Cluster Proxy: - * https://github.com/artix75/redis-cluster-proxy */ - (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info"))) { + if (!config.in_multi && + (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || + (argc >= 2 && !strcasecmp(command, "memory") && + (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || + (argc == 2 && !strcasecmp(command, "cluster") && + (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || + (argc >= 2 && !strcasecmp(command, "client") && + (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || + (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || + (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || + /* Format PROXY INFO command for Cluster Proxy: + * https://github.com/artix75/redis-cluster-proxy */ + (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info")))) { output_raw = 1; } From 61559bfcb69b56edcddfb8ecd61e5025902f4d19 Mon Sep 17 00:00:00 2001 From: xbasel <103044017+xbasel@users.noreply.github.com> Date: Wed, 26 Feb 2025 22:41:05 +0200 Subject: [PATCH 3/5] Add comment --- src/valkey-cli.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/valkey-cli.c b/src/valkey-cli.c index b8c10d8bd8..54205cbba6 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -2338,22 +2338,24 @@ static int cliSendCommand(int argc, char **argv, long repeat) { if (context == NULL) return REDIS_ERR; output_raw = 0; - if (!config.in_multi && - (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || - (argc >= 2 && !strcasecmp(command, "memory") && - (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || - (argc == 2 && !strcasecmp(command, "cluster") && - (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || - (argc >= 2 && !strcasecmp(command, "client") && - (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || - (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || - (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || - /* Format PROXY INFO command for Cluster Proxy: - * https://github.com/artix75/redis-cluster-proxy */ - (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info")))) { + if (config.in_multi) { + /* In a multi block, commands will return status instead of verbatim. */ + output_raw = 0; + } else if (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || + (argc >= 2 && !strcasecmp(command, "memory") && + (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || + (argc == 2 && !strcasecmp(command, "cluster") && + (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || + (argc >= 2 && !strcasecmp(command, "client") && + (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || + (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || + (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || + /* Format PROXY INFO command for Cluster Proxy: + * https://github.com/artix75/redis-cluster-proxy */ + (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info"))) { output_raw = 1; } From 8d2b0374b35dcb99dd1613a050e2ad3660c35399 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Wed, 26 Feb 2025 14:07:14 -0800 Subject: [PATCH 4/5] Update src/valkey-cli.c Signed-off-by: Madelyn Olson --- src/valkey-cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/valkey-cli.c b/src/valkey-cli.c index 54205cbba6..cc6213a2e8 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -2339,7 +2339,7 @@ static int cliSendCommand(int argc, char **argv, long repeat) { output_raw = 0; if (config.in_multi) { - /* In a multi block, commands will return status instead of verbatim. */ + /* In a multi block, commands will return status strings instead of verbatim strings. */ output_raw = 0; } else if (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || From 93e0eef3ea6def9115a0534756206c18d3d31cb0 Mon Sep 17 00:00:00 2001 From: Madelyn Olson Date: Wed, 26 Feb 2025 21:30:39 -0800 Subject: [PATCH 5/5] Update src/valkey-cli.c Signed-off-by: Madelyn Olson --- src/valkey-cli.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/valkey-cli.c b/src/valkey-cli.c index cc6213a2e8..a3778eefe8 100644 --- a/src/valkey-cli.c +++ b/src/valkey-cli.c @@ -2338,27 +2338,27 @@ static int cliSendCommand(int argc, char **argv, long repeat) { if (context == NULL) return REDIS_ERR; output_raw = 0; - if (config.in_multi) { - /* In a multi block, commands will return status strings instead of verbatim strings. */ - output_raw = 0; - } else if (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || - (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || - (argc >= 2 && !strcasecmp(command, "memory") && - (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || - (argc == 2 && !strcasecmp(command, "cluster") && - (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || - (argc >= 2 && !strcasecmp(command, "client") && - (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || - (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || - (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || - /* Format PROXY INFO command for Cluster Proxy: - * https://github.com/artix75/redis-cluster-proxy */ - (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info"))) { + if (!strcasecmp(command, "info") || !strcasecmp(command, "lolwut") || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "htstats-key")) || + (argc >= 2 && !strcasecmp(command, "debug") && !strcasecmp(argv[1], "client-eviction")) || + (argc >= 2 && !strcasecmp(command, "memory") && + (!strcasecmp(argv[1], "malloc-stats") || !strcasecmp(argv[1], "doctor"))) || + (argc == 2 && !strcasecmp(command, "cluster") && + (!strcasecmp(argv[1], "nodes") || !strcasecmp(argv[1], "info"))) || + (argc >= 2 && !strcasecmp(command, "client") && + (!strcasecmp(argv[1], "list") || !strcasecmp(argv[1], "info"))) || + (argc == 3 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "graph")) || + (argc == 2 && !strcasecmp(command, "latency") && !strcasecmp(argv[1], "doctor")) || + /* Format PROXY INFO command for Cluster Proxy: + * https://github.com/artix75/redis-cluster-proxy */ + (argc >= 2 && !strcasecmp(command, "proxy") && !strcasecmp(argv[1], "info"))) { output_raw = 1; } + /* In a multi block, commands will return status strings instead of verbatim strings. */ + if (config.in_multi) output_raw = 0; + if (!strcasecmp(command, "shutdown")) config.shutdown = 1; if (!strcasecmp(command, "monitor")) config.monitor_mode = 1; int is_subscribe =