From b61a28fe35232ca34632e2ad1c755e21a6eb5426 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 24 Mar 2010 21:58:34 +0100 Subject: [PATCH] Fixed the reply about denied write commands under maxmemory reached condition: now the error will no longer lead to a client-server protocol desync --- redis.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/redis.c b/redis.c index 04c2c80b..025f9dda 100644 --- a/redis.c +++ b/redis.c @@ -2187,10 +2187,6 @@ static int processCommand(redisClient *c) { cmd->name)); resetClient(c); return 1; - } else if (server.maxmemory && cmd->flags & REDIS_CMD_DENYOOM && zmalloc_used_memory() > server.maxmemory) { - addReplySds(c,sdsnew("-ERR command not allowed when used memory > 'maxmemory'\r\n")); - resetClient(c); - return 1; } else if (cmd->flags & REDIS_CMD_BULK && c->bulklen == -1) { /* This is a bulk command, we have to read the last argument yet. */ int bulklen = atoi(c->argv[c->argc-1]->ptr); @@ -2236,6 +2232,15 @@ static int processCommand(redisClient *c) { return 1; } + /* Handle the maxmemory directive */ + if (server.maxmemory && (cmd->flags & REDIS_CMD_DENYOOM) && + zmalloc_used_memory() > server.maxmemory) + { + addReplySds(c,sdsnew("-ERR command not allowed when used memory > 'maxmemory'\r\n")); + resetClient(c); + return 1; + } + /* Exec the command */ if (c->flags & REDIS_MULTI && cmd->proc != execCommand && cmd->proc != discardCommand) { queueMultiCommand(c,cmd); -- 2.45.2