From: antirez Date: Wed, 31 Oct 2012 08:23:05 +0000 (+0100) Subject: Invert two sides of if expression in SET to avoid a lookup. X-Git-Url: https://git.saurik.com/redis.git/commitdiff_plain/4d9bd5353027561039dc4583c794c8cfec30202c?hp=5bf0997ff879bf8668939d6b9e8a6eb877750c09 Invert two sides of if expression in SET to avoid a lookup. Because of the short circuit behavior of && inverting the two sides of the if expression avoids an hash table lookup if the non-EX variant of SET is called. Thanks to Weibin Yao (@yaoweibin on github) for spotting this. --- diff --git a/src/t_string.c b/src/t_string.c index 1e29a613..ba427961 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -26,7 +26,7 @@ void setGenericCommand(redisClient *c, int nx, robj *key, robj *val, robj *expir if (unit == UNIT_SECONDS) milliseconds *= 1000; } - if (lookupKeyWrite(c->db,key) != NULL && nx) { + if (nx && lookupKeyWrite(c->db,key) != NULL) { addReply(c,shared.czero); return; }