]> git.saurik.com Git - redis.git/blobdiff - src/redis.c
List connected slaves with ip,port,state information in INFO, as requested by github...
[redis.git] / src / redis.c
index b067b75fe66b85dd1ab0410b1a39107fdf8d8e42..6926458b24db9fdccc4e19b3624b34a4a5cf5d80 100644 (file)
@@ -1611,6 +1611,37 @@ sds genRedisInfoString(char *section) {
         info = sdscatprintf(info,
             "connected_slaves:%d\r\n",
             listLength(server.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++;
+            }
+        }
     }
 
     /* CPU */