From e3cedbb18ce0e5ea6bb6dbd52fea86773fcbeccf Mon Sep 17 00:00:00 2001 From: xhe Date: Tue, 9 Jun 2020 19:46:49 +0800 Subject: [PATCH] add a read-only variant for HELLO As discussed in https://github.com/antirez/redis/issues/7364, it is good to have a HELLO command variant, which does not switch the current proto version of a redis server. While `HELLO` will work, it introduced a certain difficulty on parsing options of the command. We will need to offset the index of authentication and setname option by -1. So 0 is marked a special version meaning non-switching. And we do not need to change the code much. --- src/networking.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/networking.c b/src/networking.c index 8fee298c6..e16a39a14 100644 --- a/src/networking.c +++ b/src/networking.c @@ -2763,7 +2763,7 @@ void helloCommand(client *c) { long long ver; if (getLongLongFromObject(c->argv[1],&ver) != C_OK || - ver < 2 || ver > 3) + (ver != 0 && ver < 2) || ver > 3) { addReplyError(c,"-NOPROTO unsupported protocol version"); return; @@ -2797,7 +2797,7 @@ void helloCommand(client *c) { } /* Let's switch to the specified RESP mode. */ - c->resp = ver; + if (ver != 0) c->resp = ver; addReplyMapLen(c,6 + !server.sentinel_mode); addReplyBulkCString(c,"server"); @@ -2807,7 +2807,7 @@ void helloCommand(client *c) { addReplyBulkCString(c,REDIS_VERSION); addReplyBulkCString(c,"proto"); - addReplyLongLong(c,ver); + addReplyLongLong(c,c->resp); addReplyBulkCString(c,"id"); addReplyLongLong(c,c->id);