Fix SENTINEL DEBUG with wrong arguments (#10258)

There are two issues in SENTINEL DEBUG:
1. The error message should mention SENTINEL DEBUG
2. Add missing reuturn in args parse.

```
redis> sentinel debug INFO-PERIOD aaa
(error) ERR Invalid argument 'aaa' for SENTINEL SET 'INFO-PERIOD'

redis> sentinel debug a b c d
(error) ERR Unknown option or number of arguments for SENTINEL SET 'a'
redis> ping
(error) ERR Unknown option or number of arguments for SENTINEL SET 'b'
```

Introduced in #9291. Also do some cleanups in the code.
This commit is contained in:
gms 2022-02-09 00:45:47 +08:00 committed by GitHub
parent 34c288fe11
commit 0990dec3f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 21 deletions

View File

@ -3454,7 +3454,6 @@ void addReplySentinelRedisInstance(client *c, sentinelRedisInstance *ri) {
} }
void sentinelSetDebugConfigParameters(client *c){ void sentinelSetDebugConfigParameters(client *c){
int j; int j;
int badarg = 0; /* Bad argument position for error reporting. */ int badarg = 0; /* Bad argument position for error reporting. */
char *option; char *option;
@ -3501,7 +3500,7 @@ void sentinelSetDebugConfigParameters(client *c){
} }
sentinel_publish_period = ll; sentinel_publish_period = ll;
}else if (!strcasecmp(option,"default-down-after") && moreargs > 0) { } else if (!strcasecmp(option,"default-down-after") && moreargs > 0) {
/* default-down-after <milliseconds> */ /* default-down-after <milliseconds> */
robj *o = c->argv[++j]; robj *o = c->argv[++j];
if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) { if (getLongLongFromObject(o,&ll) == C_ERR || ll <= 0) {
@ -3584,24 +3583,22 @@ void sentinelSetDebugConfigParameters(client *c){
} else { } else {
addReplyErrorFormat(c,"Unknown option or number of arguments for " addReplyErrorFormat(c,"Unknown option or number of arguments for "
"SENTINEL SET '%s'", option); "SENTINEL DEBUG '%s'", option);
return;
} }
} }
addReply(c,shared.ok); addReply(c,shared.ok);
return; return;
badfmt: /* Bad format errors */ badfmt: /* Bad format errors */
addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL SET '%s'", addReplyErrorFormat(c,"Invalid argument '%s' for SENTINEL DEBUG '%s'",
(char*)c->argv[badarg]->ptr,option); (char*)c->argv[badarg]->ptr,option);
return; return;
} }
void addReplySentinelDebugInfo(client *c) { void addReplySentinelDebugInfo(client *c) {
void *mbl; void *mbl;
int fields = 0; int fields = 0;