]> git.saurik.com Git - redis.git/blobdiff - src/networking.c
CLIENT LIST implemented
[redis.git] / src / networking.c
index 995b910cf1b510fe49bb5dbe7f135993ad7220d5..8949c9480989d0b89345ca9882f54279933cb063 100644 (file)
@@ -869,3 +869,49 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
     *biggest_input_buffer = bib;
 }
 
+void clientCommand(redisClient *c) {
+    if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
+        listNode *ln;
+        listIter li;
+        sds o = sdsempty();
+        time_t now = time(NULL);
+
+        listRewind(server.clients,&li);
+        while ((ln = listNext(&li)) != NULL) {
+            redisClient *client;
+            char ip[32], flags[16], *p;
+            int port;
+
+            client = listNodeValue(ln);
+            if (anetPeerToString(client->fd,ip,&port) == -1) continue;
+            p = flags;
+            if (client->flags & REDIS_SLAVE) {
+                if (client->flags & REDIS_MONITOR)
+                    *p++ = 'O';
+                else
+                    *p++ = 'S';
+            }
+            if (client->flags & REDIS_MASTER) *p++ = 'M';
+            if (p == flags) *p++ = 'N';
+            if (client->flags & REDIS_MULTI) *p++ = 'x';
+            if (client->flags & REDIS_BLOCKED) *p++ = 'b';
+            if (client->flags & REDIS_IO_WAIT) *p++ = 'i';
+            if (client->flags & REDIS_DIRTY_CAS) *p++ = 'd';
+            if (client->flags & REDIS_CLOSE_AFTER_REPLY) *p++ = 'c';
+            if (client->flags & REDIS_UNBLOCKED) *p++ = 'u';
+            *p++ = '\0';
+            o = sdscatprintf(o,
+                "addr=%s:%d fd=%d idle=%ld flags=%s db=%d sub=%d psub=%d\n",
+                ip,port,client->fd,
+                (long)(now - client->lastinteraction),
+                flags,
+                client->db->id,
+                (int) dictSize(client->pubsub_channels),
+                (int) listLength(client->pubsub_patterns));
+        }
+        addReplyBulkCBuffer(c,o,sdslen(o));
+        sdsfree(o);
+    } else {
+        addReplyError(c, "Syntax error, try CLIENT (LIST | KILL ip:port)");
+    }
+}