Permalink
Browse files

List connected slaves with ip,port,state information in INFO, as requ…

…ested by github issue #219
  • Loading branch information...
1 parent 273f410 commit 8b102e041aeb93b0268d5f33ac043830460ccdfc @antirez antirez committed Dec 14, 2011
Showing with 33 additions and 0 deletions.
  1. +33 −0 src/redis.c
View
@@ -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"

0 comments on commit 8b102e0

Please sign in to comment.