minor refactoring to networking.c adding a separated function to get a string representing the current state of all the connected clients.

This commit is contained in:
antirez 2011-11-24 15:04:42 +01:00
parent 2c74a9f948
commit 45e7a1ce00
2 changed files with 17 additions and 8 deletions

View File

@ -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) {

View File

@ -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);