]> git.saurik.com Git - redis.git/commitdiff
No timeouts nor other commands for clients in a Pub/Sub context
authorantirez <antirez@gmail.com>
Mon, 29 Mar 2010 15:48:13 +0000 (17:48 +0200)
committerantirez <antirez@gmail.com>
Mon, 29 Mar 2010 15:48:13 +0000 (17:48 +0200)
redis.c

diff --git a/redis.c b/redis.c
index 650e11e42fbb5561d5e1544c8d8f0cff7b347616..ecde1939ae470b2901c57e415bdb91dcf985cc70 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -1152,7 +1152,8 @@ static void closeTimedoutClients(void) {
         if (server.maxidletime &&
             !(c->flags & REDIS_SLAVE) &&    /* no timeout for slaves */
             !(c->flags & REDIS_MASTER) &&   /* no timeout for masters */
-             (now - c->lastinteraction > server.maxidletime))
+            dictSize(c->pubsub_classes) == 0 && /* no timeout for pubsub */
+            (now - c->lastinteraction > server.maxidletime))
         {
             redisLog(REDIS_VERBOSE,"Closing idle client");
             freeClient(c);
@@ -2264,6 +2265,14 @@ static int processCommand(redisClient *c) {
         return 1;
     }
 
+    /* Only allow SUBSCRIBE and UNSUBSCRIBE in the context of Pub/Sub */
+    if (dictSize(c->pubsub_classes) > 0 &&
+        cmd->proc != subscribeCommand && cmd->proc != unsubscribeCommand) {
+        addReplySds(c,sdsnew("-ERR only SUBSCRIBE / UNSUBSCRIBE / QUIT allowed in this context\r\n"));
+        resetClient(c);
+        return 1;
+    }
+
     /* Exec the command */
     if (c->flags & REDIS_MULTI && cmd->proc != execCommand && cmd->proc != discardCommand) {
         queueMultiCommand(c,cmd);