mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 17:10:50 +00:00
CG: Make XINFO Great Again (and more Redis-ish).
With XINFO out of the blue I invented a new syntax for commands never used in Redis in the past... Let's fix it and make it Great Again!!11one (TM)
This commit is contained in:
parent
2ba9a57c9a
commit
5577130451
@ -312,7 +312,7 @@ struct redisCommand redisCommandTable[] = {
|
|||||||
{"xack",xackCommand,-3,"wF",0,NULL,1,1,1,0,0},
|
{"xack",xackCommand,-3,"wF",0,NULL,1,1,1,0,0},
|
||||||
{"xpending",xpendingCommand,-3,"r",0,NULL,1,1,1,0,0},
|
{"xpending",xpendingCommand,-3,"r",0,NULL,1,1,1,0,0},
|
||||||
{"xclaim",xclaimCommand,-5,"wF",0,NULL,1,1,1,0,0},
|
{"xclaim",xclaimCommand,-5,"wF",0,NULL,1,1,1,0,0},
|
||||||
{"xinfo",xinfoCommand,-2,"r",0,NULL,1,1,1,0,0},
|
{"xinfo",xinfoCommand,-2,"r",0,NULL,2,2,1,0,0},
|
||||||
{"post",securityWarningCommand,-1,"lt",0,NULL,0,0,0,0,0},
|
{"post",securityWarningCommand,-1,"lt",0,NULL,0,0,0,0,0},
|
||||||
{"host:",securityWarningCommand,-1,"lt",0,NULL,0,0,0,0,0},
|
{"host:",securityWarningCommand,-1,"lt",0,NULL,0,0,0,0,0},
|
||||||
{"latency",latencyCommand,-2,"aslt",0,NULL,0,0,0,0,0}
|
{"latency",latencyCommand,-2,"aslt",0,NULL,0,0,0,0,0}
|
||||||
|
@ -1926,34 +1926,52 @@ void xclaimCommand(client *c) {
|
|||||||
preventCommandPropagation(c);
|
preventCommandPropagation(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XINFO <key> [CONSUMERS group|GROUPS|STREAM]. STREAM is the default */
|
/* XINFO CONSUMERS key group
|
||||||
|
* XINFO GROUPS <key>
|
||||||
|
* XINFO STREAM <key>
|
||||||
|
* XINFO <key> (alias of XINFO STREAM key)
|
||||||
|
* XINFO HELP. */
|
||||||
void xinfoCommand(client *c) {
|
void xinfoCommand(client *c) {
|
||||||
const char *help[] = {
|
const char *help[] = {
|
||||||
"<key> CONSUMERS <groupname> -- Show consumer groups of group <groupname>.",
|
"CONSUMERS <key> <groupname> -- Show consumer groups of group <groupname>.",
|
||||||
"<key> GROUPS -- Show the stream consumer groups.",
|
"GROUPS <key> -- Show the stream consumer groups.",
|
||||||
"<key> STREAM -- Show information about the stream.",
|
"STREAM <key> -- Show information about the stream.",
|
||||||
"<key> (without subcommand) -- Alias for <key> STREAM.",
|
"<key> -- Alias for STREAM <key>.",
|
||||||
"<key> HELP -- Prints this help.",
|
"HELP -- Print this help.",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
stream *s = NULL;
|
stream *s = NULL;
|
||||||
char *opt = c->argc > 2 ? c->argv[2]->ptr : "STREAM"; /* Subcommand. */
|
char *opt;
|
||||||
|
robj *key;
|
||||||
|
|
||||||
|
/* HELP is special. Handle it ASAP. */
|
||||||
|
if (!strcasecmp(c->argv[1]->ptr,"HELP")) {
|
||||||
|
addReplyHelp(c, help);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Handle the fact that no subcommand means "STREAM". */
|
||||||
|
if (c->argc == 2) {
|
||||||
|
opt = "STREAM";
|
||||||
|
key = c->argv[1];
|
||||||
|
} else {
|
||||||
|
opt = c->argv[1]->ptr;
|
||||||
|
key = c->argv[2];
|
||||||
|
}
|
||||||
|
|
||||||
/* Lookup the key now, this is common for all the subcommands but HELP. */
|
/* Lookup the key now, this is common for all the subcommands but HELP. */
|
||||||
if (c->argc >= 2 && strcasecmp(opt,"HELP")) {
|
robj *o = lookupKeyWriteOrReply(c,key,shared.nokeyerr);
|
||||||
robj *o = lookupKeyWriteOrReply(c,c->argv[1],shared.nokeyerr);
|
|
||||||
if (o == NULL) return;
|
if (o == NULL) return;
|
||||||
s = o->ptr;
|
s = o->ptr;
|
||||||
}
|
|
||||||
|
|
||||||
/* Dispatch the different subcommands. */
|
/* Dispatch the different subcommands. */
|
||||||
if (!strcasecmp(opt,"CONSUMERS") && c->argc == 4) {
|
if (!strcasecmp(opt,"CONSUMERS") && c->argc == 4) {
|
||||||
/* XINFO <key> CONSUMERS <group>. */
|
/* XINFO CONSUMERS <key> <group>. */
|
||||||
streamCG *cg = streamLookupCG(s,c->argv[3]->ptr);
|
streamCG *cg = streamLookupCG(s,c->argv[3]->ptr);
|
||||||
if (cg == NULL) {
|
if (cg == NULL) {
|
||||||
addReplyErrorFormat(c, "-NOGROUP No such consumer group '%s' "
|
addReplyErrorFormat(c, "-NOGROUP No such consumer group '%s' "
|
||||||
"for key name '%s'",
|
"for key name '%s'",
|
||||||
c->argv[3]->ptr, c->argv[1]->ptr);
|
c->argv[3]->ptr, key->ptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1977,7 +1995,7 @@ NULL
|
|||||||
}
|
}
|
||||||
raxStop(&ri);
|
raxStop(&ri);
|
||||||
} else if (!strcasecmp(opt,"GROUPS") && c->argc == 3) {
|
} else if (!strcasecmp(opt,"GROUPS") && c->argc == 3) {
|
||||||
/* XINFO <key> GROUPS. */
|
/* XINFO GROUPS <key>. */
|
||||||
if (s->cgroups == NULL) {
|
if (s->cgroups == NULL) {
|
||||||
addReplyMultiBulkLen(c,0);
|
addReplyMultiBulkLen(c,0);
|
||||||
return;
|
return;
|
||||||
@ -2001,7 +2019,7 @@ NULL
|
|||||||
} else if (c->argc == 2 ||
|
} else if (c->argc == 2 ||
|
||||||
(!strcasecmp(opt,"STREAM") && c->argc == 3))
|
(!strcasecmp(opt,"STREAM") && c->argc == 3))
|
||||||
{
|
{
|
||||||
/* XINFO <key> STREAM (or the alias XINFO <key>). */
|
/* XINFO STREAM <key> (or the alias XINFO <key>). */
|
||||||
addReplyMultiBulkLen(c,12);
|
addReplyMultiBulkLen(c,12);
|
||||||
addReplyStatus(c,"length");
|
addReplyStatus(c,"length");
|
||||||
addReplyLongLong(c,s->length);
|
addReplyLongLong(c,s->length);
|
||||||
@ -2026,10 +2044,8 @@ NULL
|
|||||||
count = streamReplyWithRange(c,s,&start,&end,1,1,NULL,NULL,
|
count = streamReplyWithRange(c,s,&start,&end,1,1,NULL,NULL,
|
||||||
STREAM_RWR_RAWENTRIES,NULL);
|
STREAM_RWR_RAWENTRIES,NULL);
|
||||||
if (!count) addReply(c,shared.nullbulk);
|
if (!count) addReply(c,shared.nullbulk);
|
||||||
} else if (!strcasecmp(opt,"HELP")) {
|
|
||||||
addReplyHelp(c, help);
|
|
||||||
} else {
|
} else {
|
||||||
addReplyError(c,"syntax error, try 'XINFO anykey HELP'");
|
addReplyError(c,"syntax error, try 'XINFO HELP'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user