Add CLIENT INFO and CLIENT LIST [id]. (#8113)
* Add CLIENT INFO subcommand. The output is identical to CLIENT LIST but provides a single line for the current client only. * Add CLIENT LIST ID [id...]. Co-authored-by: Itamar Haber <itamar@redislabs.com>
This commit is contained in:
parent
ec951cdc15
commit
bccbc5509a
@ -2331,6 +2331,7 @@ void clientCommand(client *c) {
|
|||||||
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
|
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
|
||||||
const char *help[] = {
|
const char *help[] = {
|
||||||
"ID -- Return the ID of the current connection.",
|
"ID -- Return the ID of the current connection.",
|
||||||
|
"INFO -- Return information about the current client connection.",
|
||||||
"GETNAME -- Return the name of the current connection.",
|
"GETNAME -- Return the name of the current connection.",
|
||||||
"KILL <ip:port> -- Kill connection made from <ip:port>.",
|
"KILL <ip:port> -- Kill connection made from <ip:port>.",
|
||||||
"KILL <option> <value> [option value ...] -- Kill connections. Options are:",
|
"KILL <option> <value> [option value ...] -- Kill connections. Options are:",
|
||||||
@ -2341,6 +2342,7 @@ void clientCommand(client *c) {
|
|||||||
" SKIPME (yes|no) -- Skip killing current connection (default: yes).",
|
" SKIPME (yes|no) -- Skip killing current connection (default: yes).",
|
||||||
"LIST [options ...] -- Return information about client connections. Options:",
|
"LIST [options ...] -- Return information about client connections. Options:",
|
||||||
" TYPE (normal|master|replica|pubsub) -- Return clients of specified type.",
|
" TYPE (normal|master|replica|pubsub) -- Return clients of specified type.",
|
||||||
|
" ID id [id ...] -- Return clients of specified IDs only.",
|
||||||
"PAUSE <timeout> -- Suspend all Redis clients for <timout> milliseconds.",
|
"PAUSE <timeout> -- Suspend all Redis clients for <timout> milliseconds.",
|
||||||
"REPLY (on|off|skip) -- Control the replies sent to the current connection.",
|
"REPLY (on|off|skip) -- Control the replies sent to the current connection.",
|
||||||
"SETNAME <name> -- Assign the name <name> to the current connection.",
|
"SETNAME <name> -- Assign the name <name> to the current connection.",
|
||||||
@ -2354,21 +2356,46 @@ NULL
|
|||||||
} else if (!strcasecmp(c->argv[1]->ptr,"id") && c->argc == 2) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"id") && c->argc == 2) {
|
||||||
/* CLIENT ID */
|
/* CLIENT ID */
|
||||||
addReplyLongLong(c,c->id);
|
addReplyLongLong(c,c->id);
|
||||||
|
} else if (!strcasecmp(c->argv[1]->ptr,"info") && c->argc == 2) {
|
||||||
|
/* CLIENT INFO */
|
||||||
|
sds o = catClientInfoString(sdsempty(), c);
|
||||||
|
o = sdscatlen(o,"\n",1);
|
||||||
|
addReplyVerbatim(c,o,sdslen(o),"txt");
|
||||||
|
sdsfree(o);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"list")) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"list")) {
|
||||||
/* CLIENT LIST */
|
/* CLIENT LIST */
|
||||||
int type = -1;
|
int type = -1;
|
||||||
|
sds o = NULL;
|
||||||
if (c->argc == 4 && !strcasecmp(c->argv[2]->ptr,"type")) {
|
if (c->argc == 4 && !strcasecmp(c->argv[2]->ptr,"type")) {
|
||||||
type = getClientTypeByName(c->argv[3]->ptr);
|
type = getClientTypeByName(c->argv[3]->ptr);
|
||||||
if (type == -1) {
|
if (type == -1) {
|
||||||
addReplyErrorFormat(c,"Unknown client type '%s'",
|
addReplyErrorFormat(c,"Unknown client type '%s'",
|
||||||
(char*) c->argv[3]->ptr);
|
(char*) c->argv[3]->ptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (c->argc > 3 && !strcasecmp(c->argv[2]->ptr,"id")) {
|
||||||
|
int j;
|
||||||
|
o = sdsempty();
|
||||||
|
for (j = 3; j < c->argc; j++) {
|
||||||
|
long long cid;
|
||||||
|
if (getLongLongFromObjectOrReply(c, c->argv[j], &cid,
|
||||||
|
"Invalid client ID")) {
|
||||||
|
sdsfree(o);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
client *cl = lookupClientByID(cid);
|
||||||
|
if (cl) {
|
||||||
|
o = catClientInfoString(o, cl);
|
||||||
|
o = sdscatlen(o, "\n", 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (c->argc != 2) {
|
} else if (c->argc != 2) {
|
||||||
addReply(c,shared.syntaxerr);
|
addReply(c,shared.syntaxerr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sds o = getAllClientsInfoString(type);
|
|
||||||
|
if (!o)
|
||||||
|
o = getAllClientsInfoString(type);
|
||||||
addReplyVerbatim(c,o,sdslen(o),"txt");
|
addReplyVerbatim(c,o,sdslen(o),"txt");
|
||||||
sdsfree(o);
|
sdsfree(o);
|
||||||
} else if (!strcasecmp(c->argv[1]->ptr,"reply") && c->argc == 3) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"reply") && c->argc == 3) {
|
||||||
|
@ -1304,7 +1304,8 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
|
|||||||
(!strcasecmp(argv[1],"nodes") ||
|
(!strcasecmp(argv[1],"nodes") ||
|
||||||
!strcasecmp(argv[1],"info"))) ||
|
!strcasecmp(argv[1],"info"))) ||
|
||||||
(argc >= 2 && !strcasecmp(command,"client") &&
|
(argc >= 2 && !strcasecmp(command,"client") &&
|
||||||
!strcasecmp(argv[1],"list")) ||
|
(!strcasecmp(argv[1],"list") ||
|
||||||
|
!strcasecmp(argv[1],"info"))) ||
|
||||||
(argc == 3 && !strcasecmp(command,"latency") &&
|
(argc == 3 && !strcasecmp(command,"latency") &&
|
||||||
!strcasecmp(argv[1],"graph")) ||
|
!strcasecmp(argv[1],"graph")) ||
|
||||||
(argc == 2 && !strcasecmp(command,"latency") &&
|
(argc == 2 && !strcasecmp(command,"latency") &&
|
||||||
|
@ -3,6 +3,16 @@ start_server {tags {"introspection"}} {
|
|||||||
r client list
|
r client list
|
||||||
} {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
|
} {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
|
||||||
|
|
||||||
|
test {CLIENT LIST with IDs} {
|
||||||
|
set myid [r client id]
|
||||||
|
set cl [split [r client list id $myid] "\r\n"]
|
||||||
|
assert_match "id=$myid*" [lindex $cl 0]
|
||||||
|
}
|
||||||
|
|
||||||
|
test {CLIENT INFO} {
|
||||||
|
r client info
|
||||||
|
} {*addr=*:* fd=* age=* idle=* flags=N db=9 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=* argv-mem=* obl=0 oll=0 omem=0 tot-mem=* events=r cmd=client*}
|
||||||
|
|
||||||
test {MONITOR can log executed commands} {
|
test {MONITOR can log executed commands} {
|
||||||
set rd [redis_deferring_client]
|
set rd [redis_deferring_client]
|
||||||
$rd monitor
|
$rd monitor
|
||||||
|
Loading…
x
Reference in New Issue
Block a user