Merge pull request #1966 from mattsta/fix-sentinel-info

Sentinel: Improve INFO command behavior
This commit is contained in:
Salvatore Sanfilippo 2015-02-24 17:20:09 +01:00
commit 46bd13b806

View File

@ -2856,24 +2856,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;