mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
Merge pull request #5075 from soloestoy/client-list-types
FEATURE: implements client list type option
This commit is contained in:
commit
a0b05a0424
@ -1077,7 +1077,7 @@ void sigsegvHandler(int sig, siginfo_t *info, void *secret) {
|
|||||||
infostring = genRedisInfoString("all");
|
infostring = genRedisInfoString("all");
|
||||||
serverLogRaw(LL_WARNING|LL_RAW, infostring);
|
serverLogRaw(LL_WARNING|LL_RAW, infostring);
|
||||||
serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n");
|
serverLogRaw(LL_WARNING|LL_RAW, "\n------ CLIENT LIST OUTPUT ------\n");
|
||||||
clients = getAllClientsInfoString();
|
clients = getAllClientsInfoString(-1);
|
||||||
serverLogRaw(LL_WARNING|LL_RAW, clients);
|
serverLogRaw(LL_WARNING|LL_RAW, clients);
|
||||||
sdsfree(infostring);
|
sdsfree(infostring);
|
||||||
sdsfree(clients);
|
sdsfree(clients);
|
||||||
|
@ -1506,6 +1506,7 @@ sds catClientInfoString(sds s, client *client) {
|
|||||||
*p++ = 'S';
|
*p++ = 'S';
|
||||||
}
|
}
|
||||||
if (client->flags & CLIENT_MASTER) *p++ = 'M';
|
if (client->flags & CLIENT_MASTER) *p++ = 'M';
|
||||||
|
if (client->flags & CLIENT_PUBSUB) *p++ = 'P';
|
||||||
if (client->flags & CLIENT_MULTI) *p++ = 'x';
|
if (client->flags & CLIENT_MULTI) *p++ = 'x';
|
||||||
if (client->flags & CLIENT_BLOCKED) *p++ = 'b';
|
if (client->flags & CLIENT_BLOCKED) *p++ = 'b';
|
||||||
if (client->flags & CLIENT_DIRTY_CAS) *p++ = 'd';
|
if (client->flags & CLIENT_DIRTY_CAS) *p++ = 'd';
|
||||||
@ -1544,7 +1545,7 @@ sds catClientInfoString(sds s, client *client) {
|
|||||||
client->lastcmd ? client->lastcmd->name : "NULL");
|
client->lastcmd ? client->lastcmd->name : "NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
sds getAllClientsInfoString(void) {
|
sds getAllClientsInfoString(int type) {
|
||||||
listNode *ln;
|
listNode *ln;
|
||||||
listIter li;
|
listIter li;
|
||||||
client *client;
|
client *client;
|
||||||
@ -1553,6 +1554,7 @@ sds getAllClientsInfoString(void) {
|
|||||||
listRewind(server.clients,&li);
|
listRewind(server.clients,&li);
|
||||||
while ((ln = listNext(&li)) != NULL) {
|
while ((ln = listNext(&li)) != NULL) {
|
||||||
client = listNodeValue(ln);
|
client = listNodeValue(ln);
|
||||||
|
if (type != -1 && getClientType(client) != type) continue;
|
||||||
o = catClientInfoString(o,client);
|
o = catClientInfoString(o,client);
|
||||||
o = sdscatlen(o,"\n",1);
|
o = sdscatlen(o,"\n",1);
|
||||||
}
|
}
|
||||||
@ -1574,6 +1576,7 @@ void clientCommand(client *c) {
|
|||||||
" type (normal|master|slave|pubsub) -- Kill connections by type.",
|
" type (normal|master|slave|pubsub) -- Kill connections by type.",
|
||||||
" skipme (yes|no) -- Skip killing current connection (default: yes).",
|
" skipme (yes|no) -- Skip killing current connection (default: yes).",
|
||||||
"list -- Return information about client connections.",
|
"list -- Return information about client connections.",
|
||||||
|
" type (normal|master|slave|pubsub) -- Return information about client connections by type.",
|
||||||
"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.",
|
||||||
@ -1584,9 +1587,21 @@ 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,"list") && c->argc == 2) {
|
} else if (!strcasecmp(c->argv[1]->ptr,"list")) {
|
||||||
/* CLIENT LIST */
|
/* CLIENT LIST */
|
||||||
sds o = getAllClientsInfoString();
|
int type = -1;
|
||||||
|
if (c->argc == 4 && !strcasecmp(c->argv[2]->ptr,"type")) {
|
||||||
|
type = getClientTypeByName(c->argv[3]->ptr);
|
||||||
|
if (type == -1) {
|
||||||
|
addReplyErrorFormat(c,"Unknown client type '%s'",
|
||||||
|
(char*) c->argv[3]->ptr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (c->argc != 2) {
|
||||||
|
addReply(c,shared.syntaxerr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sds o = getAllClientsInfoString(type);
|
||||||
addReplyBulkCBuffer(c,o,sdslen(o));
|
addReplyBulkCBuffer(c,o,sdslen(o));
|
||||||
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) {
|
||||||
|
@ -1089,7 +1089,7 @@ static int cliSendCommand(int argc, char **argv, long repeat) {
|
|||||||
(argc == 2 && !strcasecmp(command,"cluster") &&
|
(argc == 2 && !strcasecmp(command,"cluster") &&
|
||||||
(!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")) ||
|
||||||
(argc == 3 && !strcasecmp(command,"latency") &&
|
(argc == 3 && !strcasecmp(command,"latency") &&
|
||||||
!strcasecmp(argv[1],"graph")) ||
|
!strcasecmp(argv[1],"graph")) ||
|
||||||
|
@ -1421,7 +1421,7 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
|
|||||||
unsigned long *biggest_input_buffer);
|
unsigned long *biggest_input_buffer);
|
||||||
char *getClientPeerId(client *client);
|
char *getClientPeerId(client *client);
|
||||||
sds catClientInfoString(sds s, client *client);
|
sds catClientInfoString(sds s, client *client);
|
||||||
sds getAllClientsInfoString(void);
|
sds getAllClientsInfoString(int type);
|
||||||
void rewriteClientCommandVector(client *c, int argc, ...);
|
void rewriteClientCommandVector(client *c, int argc, ...);
|
||||||
void rewriteClientCommandArgument(client *c, int i, robj *newval);
|
void rewriteClientCommandArgument(client *c, int i, robj *newval);
|
||||||
void replaceClientCommandVector(client *c, int argc, robj **argv);
|
void replaceClientCommandVector(client *c, int argc, robj **argv);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user