Make the protocol-version argument of HELLO optional (#7377)
This commit is contained in:
commit
19d4705ffd
@ -2820,18 +2820,24 @@ NULL
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* HELLO <protocol-version> [AUTH <user> <password>] [SETNAME <name>] */
|
/* HELLO [<protocol-version> [AUTH <user> <password>] [SETNAME <name>] ] */
|
||||||
void helloCommand(client *c) {
|
void helloCommand(client *c) {
|
||||||
long long ver;
|
long long ver = 0;
|
||||||
|
int next_arg = 1;
|
||||||
|
|
||||||
if (getLongLongFromObject(c->argv[1],&ver) != C_OK ||
|
if (c->argc >= 2) {
|
||||||
ver < 2 || ver > 3)
|
if (getLongLongFromObjectOrReply(c, c->argv[next_arg++], &ver,
|
||||||
{
|
"Protocol version is not an integer or out of range") != C_OK) {
|
||||||
addReplyError(c,"-NOPROTO unsupported protocol version");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 2; j < c->argc; j++) {
|
if (ver < 2 || ver > 3) {
|
||||||
|
addReplyError(c,"-NOPROTO unsupported protocol version");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int j = next_arg; j < c->argc; j++) {
|
||||||
int moreargs = (c->argc-1) - j;
|
int moreargs = (c->argc-1) - j;
|
||||||
const char *opt = c->argv[j]->ptr;
|
const char *opt = c->argv[j]->ptr;
|
||||||
if (!strcasecmp(opt,"AUTH") && moreargs >= 2) {
|
if (!strcasecmp(opt,"AUTH") && moreargs >= 2) {
|
||||||
@ -2859,7 +2865,7 @@ void helloCommand(client *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Let's switch to the specified RESP mode. */
|
/* Let's switch to the specified RESP mode. */
|
||||||
c->resp = ver;
|
if (ver) c->resp = ver;
|
||||||
addReplyMapLen(c,6 + !server.sentinel_mode);
|
addReplyMapLen(c,6 + !server.sentinel_mode);
|
||||||
|
|
||||||
addReplyBulkCString(c,"server");
|
addReplyBulkCString(c,"server");
|
||||||
@ -2869,7 +2875,7 @@ void helloCommand(client *c) {
|
|||||||
addReplyBulkCString(c,REDIS_VERSION);
|
addReplyBulkCString(c,REDIS_VERSION);
|
||||||
|
|
||||||
addReplyBulkCString(c,"proto");
|
addReplyBulkCString(c,"proto");
|
||||||
addReplyLongLong(c,ver);
|
addReplyLongLong(c,c->resp);
|
||||||
|
|
||||||
addReplyBulkCString(c,"id");
|
addReplyBulkCString(c,"id");
|
||||||
addReplyLongLong(c,c->id);
|
addReplyLongLong(c,c->id);
|
||||||
|
@ -469,7 +469,7 @@ struct redisCommand sentinelcmds[] = {
|
|||||||
{"client",clientCommand,-2,"admin random @connection",0,NULL,0,0,0,0,0},
|
{"client",clientCommand,-2,"admin random @connection",0,NULL,0,0,0,0,0},
|
||||||
{"shutdown",shutdownCommand,-1,"admin",0,NULL,0,0,0,0,0},
|
{"shutdown",shutdownCommand,-1,"admin",0,NULL,0,0,0,0,0},
|
||||||
{"auth",authCommand,-2,"no-auth fast @connection",0,NULL,0,0,0,0,0},
|
{"auth",authCommand,-2,"no-auth fast @connection",0,NULL,0,0,0,0,0},
|
||||||
{"hello",helloCommand,-2,"no-auth fast @connection",0,NULL,0,0,0,0,0},
|
{"hello",helloCommand,-1,"no-auth fast @connection",0,NULL,0,0,0,0,0},
|
||||||
{"acl",aclCommand,-2,"admin",0,NULL,0,0,0,0,0,0},
|
{"acl",aclCommand,-2,"admin",0,NULL,0,0,0,0,0,0},
|
||||||
{"command",commandCommand,-1, "random @connection", 0,NULL,0,0,0,0,0,0}
|
{"command",commandCommand,-1, "random @connection", 0,NULL,0,0,0,0,0,0}
|
||||||
};
|
};
|
||||||
|
@ -869,7 +869,7 @@ struct redisCommand redisCommandTable[] = {
|
|||||||
"admin no-script random ok-loading ok-stale @connection",
|
"admin no-script random ok-loading ok-stale @connection",
|
||||||
0,NULL,0,0,0,0,0,0},
|
0,NULL,0,0,0,0,0,0},
|
||||||
|
|
||||||
{"hello",helloCommand,-2,
|
{"hello",helloCommand,-1,
|
||||||
"no-auth no-script fast no-monitor ok-loading ok-stale no-slowlog @connection",
|
"no-auth no-script fast no-monitor ok-loading ok-stale no-slowlog @connection",
|
||||||
0,NULL,0,0,0,0,0,0},
|
0,NULL,0,0,0,0,0,0},
|
||||||
|
|
||||||
|
@ -135,6 +135,32 @@ start_server {tags {"tracking"}} {
|
|||||||
assert {[lindex $reply 2] eq {proto 3}}
|
assert {[lindex $reply 2] eq {proto 3}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {HELLO without protover} {
|
||||||
|
set reply [r HELLO 3]
|
||||||
|
assert {[lindex $reply 2] eq {proto 3}}
|
||||||
|
|
||||||
|
set reply [r HELLO]
|
||||||
|
assert {[lindex $reply 2] eq {proto 3}}
|
||||||
|
|
||||||
|
set reply [r HELLO]
|
||||||
|
assert {[lindex $reply 2] eq {proto 3}}
|
||||||
|
|
||||||
|
set reply [r HELLO 2]
|
||||||
|
assert {[lindex $reply 4] eq "proto"}
|
||||||
|
assert {[lindex $reply 5] eq 2}
|
||||||
|
|
||||||
|
set reply [r HELLO]
|
||||||
|
assert {[lindex $reply 4] eq "proto"}
|
||||||
|
assert {[lindex $reply 5] eq 2}
|
||||||
|
|
||||||
|
set reply [r HELLO]
|
||||||
|
assert {[lindex $reply 4] eq "proto"}
|
||||||
|
assert {[lindex $reply 5] eq 2}
|
||||||
|
|
||||||
|
# restore RESP3 for next test
|
||||||
|
r HELLO 3
|
||||||
|
}
|
||||||
|
|
||||||
test {RESP3 based basic invalidation} {
|
test {RESP3 based basic invalidation} {
|
||||||
r CLIENT TRACKING off
|
r CLIENT TRACKING off
|
||||||
r CLIENT TRACKING on
|
r CLIENT TRACKING on
|
||||||
|
Loading…
x
Reference in New Issue
Block a user