Sentinel: make SENTINEL SET able to handle different arities.

This commit is contained in:
antirez 2018-06-25 17:12:39 +02:00
parent c303e768bf
commit 903582dd7b

View File

@ -3180,7 +3180,7 @@ void sentinelCommand(client *c) {
addReplySds(c,e); addReplySds(c,e);
} }
} else if (!strcasecmp(c->argv[1]->ptr,"set")) { } else if (!strcasecmp(c->argv[1]->ptr,"set")) {
if (c->argc < 3 || c->argc % 2 == 0) goto numargserr; if (c->argc < 3) goto numargserr;
sentinelSetCommand(c); sentinelSetCommand(c);
} else if (!strcasecmp(c->argv[1]->ptr,"info-cache")) { } else if (!strcasecmp(c->argv[1]->ptr,"info-cache")) {
/* SENTINEL INFO-CACHE <name> */ /* SENTINEL INFO-CACHE <name> */
@ -3385,33 +3385,37 @@ void sentinelSetCommand(client *c) {
== NULL) return; == NULL) return;
/* Process option - value pairs. */ /* Process option - value pairs. */
for (j = 3; j < c->argc; j += 2) { for (j = 3; j < c->argc; j++) {
int moreargs = (c->argc-1) - j;
option = c->argv[j]->ptr; option = c->argv[j]->ptr;
value = c->argv[j+1]->ptr;
robj *o = c->argv[j+1]; robj *o = c->argv[j+1];
long long ll; long long ll;
if (!strcasecmp(option,"down-after-milliseconds")) { if (!strcasecmp(option,"down-after-milliseconds") && moreargs > 0) {
/* down-after-millisecodns <milliseconds> */ /* down-after-millisecodns <milliseconds> */
value = c->argv[++j]->ptr;
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->down_after_period = ll; ri->down_after_period = ll;
sentinelPropagateDownAfterPeriod(ri); sentinelPropagateDownAfterPeriod(ri);
changes++; changes++;
} else if (!strcasecmp(option,"failover-timeout")) { } else if (!strcasecmp(option,"failover-timeout") && moreargs > 0) {
/* failover-timeout <milliseconds> */ /* failover-timeout <milliseconds> */
value = c->argv[++j]->ptr;
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->failover_timeout = ll; ri->failover_timeout = ll;
changes++; changes++;
} else if (!strcasecmp(option,"parallel-syncs")) { } else if (!strcasecmp(option,"parallel-syncs") && moreargs > 0) {
/* parallel-syncs <milliseconds> */ /* parallel-syncs <milliseconds> */
value = c->argv[++j]->ptr;
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->parallel_syncs = ll; ri->parallel_syncs = ll;
changes++; changes++;
} else if (!strcasecmp(option,"notification-script")) { } else if (!strcasecmp(option,"notification-script") && moreargs > 0) {
/* notification-script <path> */ /* notification-script <path> */
value = c->argv[++j]->ptr;
if (sentinel.deny_scripts_reconfig) { if (sentinel.deny_scripts_reconfig) {
addReplyError(c, addReplyError(c,
"Reconfiguration of scripts path is denied for " "Reconfiguration of scripts path is denied for "
@ -3429,8 +3433,9 @@ void sentinelSetCommand(client *c) {
sdsfree(ri->notification_script); sdsfree(ri->notification_script);
ri->notification_script = strlen(value) ? sdsnew(value) : NULL; ri->notification_script = strlen(value) ? sdsnew(value) : NULL;
changes++; changes++;
} else if (!strcasecmp(option,"client-reconfig-script")) { } else if (!strcasecmp(option,"client-reconfig-script") && moreargs > 0) {
/* client-reconfig-script <path> */ /* client-reconfig-script <path> */
value = c->argv[++j]->ptr;
if (sentinel.deny_scripts_reconfig) { if (sentinel.deny_scripts_reconfig) {
addReplyError(c, addReplyError(c,
"Reconfiguration of scripts path is denied for " "Reconfiguration of scripts path is denied for "
@ -3449,20 +3454,22 @@ void sentinelSetCommand(client *c) {
sdsfree(ri->client_reconfig_script); sdsfree(ri->client_reconfig_script);
ri->client_reconfig_script = strlen(value) ? sdsnew(value) : NULL; ri->client_reconfig_script = strlen(value) ? sdsnew(value) : NULL;
changes++; changes++;
} else if (!strcasecmp(option,"auth-pass")) { } else if (!strcasecmp(option,"auth-pass") && moreargs > 0) {
/* auth-pass <password> */ /* auth-pass <password> */
value = c->argv[++j]->ptr;
sdsfree(ri->auth_pass); sdsfree(ri->auth_pass);
ri->auth_pass = strlen(value) ? sdsnew(value) : NULL; ri->auth_pass = strlen(value) ? sdsnew(value) : NULL;
changes++; changes++;
} else if (!strcasecmp(option,"quorum")) { } else if (!strcasecmp(option,"quorum") && moreargs > 0) {
/* quorum <count> */ /* quorum <count> */
value = c->argv[++j]->ptr;
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0)
goto badfmt; goto badfmt;
ri->quorum = ll; ri->quorum = ll;
changes++; changes++;
} else { } else {
addReplyErrorFormat(c,"Unknown option '%s' for SENTINEL SET", addReplyErrorFormat(c,"Unknown option or number of arguments for "
option); "SENTINEL SET '%s'", option);
if (changes) sentinelFlushConfig(); if (changes) sentinelFlushConfig();
return; return;
} }