]> git.saurik.com Git - redis.git/commitdiff
Invert two sides of if expression in SET to avoid a lookup.
authorantirez <antirez@gmail.com>
Wed, 31 Oct 2012 08:23:05 +0000 (09:23 +0100)
committerantirez <antirez@gmail.com>
Wed, 31 Oct 2012 08:23:05 +0000 (09:23 +0100)
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.

src/t_string.c

index 1e29a61334791624272e02a64506c0c43903412a..ba42796130c70af0476e882be69b7119528f17b3 100644 (file)
@@ -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;
     }