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.
This commit is contained in:
xhe 2020-06-09 19:46:49 +08:00
parent 59ff42c421
commit b3dc23c5a8

View File

@ -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);