mirror of
https://github.com/fluencelabs/redis
synced 2025-03-30 14:21:04 +00:00
Sentinel: Improve INFO command behavior
Improvements: - Return empty string if asking for non-existing section (INFO foo) - Fix potential memory leak (caused by sdsempty() then returned if >2 args) - Clean up argument parsing - Allow "all" as valid section (same as "default" or zero args currently) - Move strcasecmp to end of evaluation chain in conditionals Also, since we're C99, I moved some variable declarations to be closer to where they are actually used (saves us from needing to free an empty info if detect argument errors up front). Closes #1915 Closes #1966
This commit is contained in:
parent
3cd36a4dd9
commit
391fc9b633
@ -2853,24 +2853,30 @@ numargserr:
|
|||||||
|
|
||||||
/* SENTINEL INFO [section] */
|
/* SENTINEL INFO [section] */
|
||||||
void sentinelInfoCommand(redisClient *c) {
|
void sentinelInfoCommand(redisClient *c) {
|
||||||
char *section = c->argc == 2 ? c->argv[1]->ptr : "default";
|
|
||||||
sds info = sdsempty();
|
|
||||||
int defsections = !strcasecmp(section,"default");
|
|
||||||
int sections = 0;
|
|
||||||
|
|
||||||
if (c->argc > 2) {
|
if (c->argc > 2) {
|
||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(section,"server") || defsections) {
|
int defsections = 0, allsections = 0;
|
||||||
|
char *section = c->argc == 2 ? c->argv[1]->ptr : NULL;
|
||||||
|
if (section) {
|
||||||
|
allsections = !strcasecmp(section,"all");
|
||||||
|
defsections = !strcasecmp(section,"default");
|
||||||
|
} else {
|
||||||
|
defsections = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sections = 0;
|
||||||
|
sds info = sdsempty();
|
||||||
|
if (defsections || allsections || !strcasecmp(section,"server")) {
|
||||||
if (sections++) info = sdscat(info,"\r\n");
|
if (sections++) info = sdscat(info,"\r\n");
|
||||||
sds serversection = genRedisInfoString("server");
|
sds serversection = genRedisInfoString("server");
|
||||||
info = sdscatlen(info,serversection,sdslen(serversection));
|
info = sdscatlen(info,serversection,sdslen(serversection));
|
||||||
sdsfree(serversection);
|
sdsfree(serversection);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(section,"sentinel") || defsections) {
|
if (defsections || allsections || !strcasecmp(section,"sentinel")) {
|
||||||
dictIterator *di;
|
dictIterator *di;
|
||||||
dictEntry *de;
|
dictEntry *de;
|
||||||
int master_id = 0;
|
int master_id = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user