]> git.saurik.com Git - redis.git/commitdiff
Don't decode object on STRLEN when not necessary
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Tue, 14 Dec 2010 09:31:11 +0000 (10:31 +0100)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Tue, 14 Dec 2010 09:42:41 +0000 (10:42 +0100)
src/t_string.c

index 3b91f5e6d3392b2078c600b5c0f3c5d4debd79f5..d537c8b909fe20942dfa615c18fcf26549157638 100644 (file)
@@ -358,7 +358,14 @@ void strlenCommand(redisClient *c) {
     if ((o = lookupKeyReadOrReply(c,c->argv[1],shared.czero)) == NULL ||
         checkType(c,o,REDIS_STRING)) return;
 
-    o = getDecodedObject(o);
-    addReplyLongLong(c,sdslen(o->ptr));
-    decrRefCount(o);
+    if (o->encoding == REDIS_ENCODING_RAW) {
+        addReplyLongLong(c,sdslen(o->ptr));
+    } else if (o->encoding == REDIS_ENCODING_INT) {
+        char llbuf[32];
+        int len = ll2string(llbuf,sizeof(llbuf),(long)o->ptr);
+        addReplyLongLong(c,len);
+    } else {
+        redisPanic("Unknown string encoding");
+    }
 }
+