diff options
author | antirez <antirez@gmail.com> | 2011-11-24 15:04:42 +0100 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2011-11-24 15:47:55 +0100 |
commit | f4e2abfcd490771c66f9c6bc2b47b7c20ff82a8c (patch) | |
tree | 4bd6826a2186d1623787d5e81aa25b210fe1748d | |
parent | 3852e2a831bbcd1ef089f4494704ebc5ee28520b (diff) | |
download | redis-f4e2abfcd490771c66f9c6bc2b47b7c20ff82a8c.tar.gz |
minor refactoring to networking.c adding a separated function to get a string representing the current state of all the connected clients.
-rw-r--r-- | src/networking.c | 24 | ||||
-rw-r--r-- | src/redis.h | 1 |
2 files changed, 17 insertions, 8 deletions
diff --git a/src/networking.c b/src/networking.c index ead9667a5..c434714be 100644 --- a/src/networking.c +++ b/src/networking.c @@ -939,20 +939,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 8bf4328ff..aff39fc77 100644 --- a/src/redis.h +++ b/src/redis.h @@ -703,6 +703,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, ...); #ifdef __GNUC__ |