Fixed the reply about denied write commands under maxmemory reached condition: now the error will no longer lead to a client-server protocol desync

This commit is contained in:
antirez 2010-03-24 21:58:34 +01:00
parent 500ece7c17
commit b61a28fe35

13
redis.c
View File

@ -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);