No timeouts nor other commands for clients in a Pub/Sub context

This commit is contained in:
antirez 2010-03-29 17:48:13 +02:00
parent ff767a7580
commit d6cc8867b7

11
redis.c
View File

@ -1152,7 +1152,8 @@ static void closeTimedoutClients(void) {
if (server.maxidletime && if (server.maxidletime &&
!(c->flags & REDIS_SLAVE) && /* no timeout for slaves */ !(c->flags & REDIS_SLAVE) && /* no timeout for slaves */
!(c->flags & REDIS_MASTER) && /* no timeout for masters */ !(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"); redisLog(REDIS_VERBOSE,"Closing idle client");
freeClient(c); freeClient(c);
@ -2264,6 +2265,14 @@ static int processCommand(redisClient *c) {
return 1; 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 */ /* Exec the command */
if (c->flags & REDIS_MULTI && cmd->proc != execCommand && cmd->proc != discardCommand) { if (c->flags & REDIS_MULTI && cmd->proc != execCommand && cmd->proc != discardCommand) {
queueMultiCommand(c,cmd); queueMultiCommand(c,cmd);