From 45e7a1ce00380ccf5f41080d69c655e120aacad6 Mon Sep 17 00:00:00 2001 From: antirez Date: Thu, 24 Nov 2011 15:04:42 +0100 Subject: [PATCH] minor refactoring to networking.c adding a separated function to get a string representing the current state of all the connected clients. --- src/networking.c | 24 ++++++++++++++++-------- src/redis.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/networking.c b/src/networking.c index 77a705b2..c16e182f 100644 --- a/src/networking.c +++ b/src/networking.c @@ -980,20 +980,28 @@ sds getClientInfoString(redisClient *client) { client->lastcmd ? client->lastcmd->name : "NULL"); } +sds getAllClientsInfoString(void) { + listNode *ln; + listIter li; + redisClient *client; + sds o = sdsempty(); + + listRewind(server.clients,&li); + while ((ln = listNext(&li)) != NULL) { + client = listNodeValue(ln); + o = sdscatsds(o,getClientInfoString(client)); + o = sdscatlen(o,"\n",1); + } + return o; +} + void clientCommand(redisClient *c) { listNode *ln; listIter li; redisClient *client; if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) { - sds o = sdsempty(); - - listRewind(server.clients,&li); - while ((ln = listNext(&li)) != NULL) { - client = listNodeValue(ln); - o = sdscatsds(o,getClientInfoString(client)); - o = sdscatlen(o,"\n",1); - } + sds o = getAllClientsInfoString(); addReplyBulkCBuffer(c,o,sdslen(o)); sdsfree(o); } else if (!strcasecmp(c->argv[1]->ptr,"kill") && c->argc == 3) { diff --git a/src/redis.h b/src/redis.h index ae1e75ba..218d72fb 100644 --- a/src/redis.h +++ b/src/redis.h @@ -769,6 +769,7 @@ void *dupClientReplyValue(void *o); void getClientsMaxBuffers(unsigned long *longest_output_list, unsigned long *biggest_input_buffer); sds getClientInfoString(redisClient *client); +sds getAllClientsInfoString(void); void rewriteClientCommandVector(redisClient *c, int argc, ...); void rewriteClientCommandArgument(redisClient *c, int i, robj *newval); -- 2.45.2