]> git.saurik.com Git - redis.git/blobdiff - src/networking.c
CLIENT KILL implemented
[redis.git] / src / networking.c
index 8949c9480989d0b89345ca9882f54279933cb063..32d071bdecffe6b50532507be2c2988f4678d0a6 100644 (file)
@@ -870,15 +870,16 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
 }
 
 void clientCommand(redisClient *c) {
 }
 
 void clientCommand(redisClient *c) {
+    listNode *ln;
+    listIter li;
+    redisClient *client;
+
     if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
     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) {
         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;
 
             char ip[32], flags[16], *p;
             int port;
 
@@ -911,6 +912,26 @@ void clientCommand(redisClient *c) {
         }
         addReplyBulkCBuffer(c,o,sdslen(o));
         sdsfree(o);
         }
         addReplyBulkCBuffer(c,o,sdslen(o));
         sdsfree(o);
+    } else if (!strcasecmp(c->argv[1]->ptr,"kill") && c->argc == 3) {
+        listRewind(server.clients,&li);
+        while ((ln = listNext(&li)) != NULL) {
+            char ip[32], addr[64];
+            int port;
+
+            client = listNodeValue(ln);
+            if (anetPeerToString(client->fd,ip,&port) == -1) continue;
+            snprintf(addr,sizeof(addr),"%s:%d",ip,port);
+            if (strcmp(addr,c->argv[2]->ptr) == 0) {
+                addReply(c,shared.ok);
+                if (c == client) {
+                    client->flags |= REDIS_CLOSE_AFTER_REPLY;
+                } else {
+                    freeClient(client);
+                }
+                return;
+            }
+        }
+        addReplyError(c,"No such client");
     } else {
         addReplyError(c, "Syntax error, try CLIENT (LIST | KILL ip:port)");
     }
     } else {
         addReplyError(c, "Syntax error, try CLIENT (LIST | KILL ip:port)");
     }