From d6cc8867b7e9d5372ff4f926a89ae9b17803df80 Mon Sep 17 00:00:00 2001 From: antirez Date: Mon, 29 Mar 2010 17:48:13 +0200 Subject: [PATCH] No timeouts nor other commands for clients in a Pub/Sub context --- redis.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/redis.c b/redis.c index 650e11e4..ecde1939 100644 --- 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);