From 8b102e041aeb93b0268d5f33ac043830460ccdfc Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 14 Dec 2011 15:11:11 +0100 Subject: [PATCH] List connected slaves with ip,port,state information in INFO, as requested by github issue #219 --- src/redis.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/redis.c b/src/redis.c index 8dda3018..24e4fede 100644 --- a/src/redis.c +++ b/src/redis.c @@ -1349,6 +1349,39 @@ sds genRedisInfoString(void) { bioPendingJobsOfType(REDIS_BIO_AOF_FSYNC)); } + /* List connected slaves */ + if (listLength(server.slaves)) { + int slaveid = 0; + listNode *ln; + listIter li; + + listRewind(server.slaves,&li); + while((ln = listNext(&li))) { + redisClient *slave = listNodeValue(ln); + char *state = NULL; + char ip[32]; + int port; + + if (anetPeerToString(slave->fd,ip,&port) == -1) continue; + switch(slave->replstate) { + case REDIS_REPL_WAIT_BGSAVE_START: + case REDIS_REPL_WAIT_BGSAVE_END: + state = "wait_bgsave"; + break; + case REDIS_REPL_SEND_BULK: + state = "send_bulk"; + break; + case REDIS_REPL_ONLINE: + state = "online"; + break; + } + if (state == NULL) continue; + info = sdscatprintf(info,"slave%d:%s,%d,%s\r\n", + slaveid,ip,port,state); + slaveid++; + } + } + if (server.masterhost) { info = sdscatprintf(info, "master_host:%s\r\n"