]> git.saurik.com Git - redis.git/blobdiff - src/networking.c
Fixed command table for SETEX and PSETEX causing the expire time to be hashed by...
[redis.git] / src / networking.c
index 3e698cd58fc61e5fd4be835d4e1f7ac6b1332c34..537ebaba65a35286d6f09c4d9e515a1bf3dd8198 100644 (file)
@@ -774,11 +774,10 @@ int processMultibulkBuffer(redisClient *c) {
                  * avoiding a large copy of data. */
                 c->querybuf = sdsrange(c->querybuf,pos,-1);
                 pos = 0;
-            }
-            /* Hint the sds library about the amount of bytes this string is
-             * going to contain. */
-            if (ll >= REDIS_MBULK_BIG_ARG)
+                /* Hint the sds library about the amount of bytes this string is
+                 * going to contain. */
                 c->querybuf = sdsMakeRoomFor(c->querybuf,ll+2);
+            }
             c->bulklen = ll;
         }
 
@@ -904,6 +903,13 @@ void readQueryFromClient(aeEventLoop *el, int fd, void *privdata, int mask) {
     } else {
         return;
     }
+    if (sdslen(c->querybuf) > server.client_max_querybuf_len) {
+        sds ci = getClientInfoString(c);
+        redisLog(REDIS_WARNING,"Closing client that reached max query buffer length: %s", ci);
+        sdsfree(ci);
+        freeClient(c);
+        return;
+    }
     processInputBuffer(c);
 }
 
@@ -925,6 +931,53 @@ void getClientsMaxBuffers(unsigned long *longest_output_list,
     *biggest_input_buffer = bib;
 }
 
+/* Turn a Redis client into an sds string representing its state. */
+sds getClientInfoString(redisClient *client) {
+    char ip[32], flags[16], events[3], *p;
+    int port;
+    time_t now = time(NULL);
+    int emask;
+
+    if (anetPeerToString(client->fd,ip,&port) == -1) {
+        ip[0] = '?';
+        ip[1] = '\0';
+        port = 0;
+    }
+    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 (client->flags & REDIS_MULTI) *p++ = 'x';
+    if (client->flags & REDIS_BLOCKED) *p++ = 'b';
+    if (client->flags & REDIS_DIRTY_CAS) *p++ = 'd';
+    if (client->flags & REDIS_CLOSE_AFTER_REPLY) *p++ = 'c';
+    if (client->flags & REDIS_UNBLOCKED) *p++ = 'u';
+    if (p == flags) *p++ = 'N';
+    *p++ = '\0';
+
+    emask = client->fd == -1 ? 0 : aeGetFileEvents(server.el,client->fd);
+    p = events;
+    if (emask & AE_READABLE) *p++ = 'r';
+    if (emask & AE_WRITABLE) *p++ = 'w';
+    *p = '\0';
+    return sdscatprintf(sdsempty(),
+        "addr=%s:%d fd=%d idle=%ld flags=%s db=%d sub=%d psub=%d qbuf=%lu obl=%lu oll=%lu events=%s",
+        ip,port,client->fd,
+        (long)(now - client->lastinteraction),
+        flags,
+        client->db->id,
+        (int) dictSize(client->pubsub_channels),
+        (int) listLength(client->pubsub_patterns),
+        (unsigned long) sdslen(client->querybuf),
+        (unsigned long) client->bufpos,
+        (unsigned long) listLength(client->reply),
+        events);
+}
+
 void clientCommand(redisClient *c) {
     listNode *ln;
     listIter li;
@@ -932,38 +985,12 @@ void clientCommand(redisClient *c) {
 
     if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
         sds o = sdsempty();
-        time_t now = time(NULL);
 
         listRewind(server.clients,&li);
         while ((ln = listNext(&li)) != NULL) {
-            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_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));
+            o = sdscatsds(o,getClientInfoString(client));
+            o = sdscatlen(o,"\n",1);
         }
         addReplyBulkCBuffer(c,o,sdslen(o));
         sdsfree(o);