From 7ecd4644e7fe48309d4b8445ec62c7fe8c0443ff Mon Sep 17 00:00:00 2001 From: Pieter Noordhuis Date: Tue, 14 Dec 2010 10:31:11 +0100 Subject: [PATCH] Don't decode object on STRLEN when not necessary --- src/t_string.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/t_string.c b/src/t_string.c index 3b91f5e6d..d537c8b90 100644 --- a/src/t_string.c +++ b/src/t_string.c @@ -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"); + } } +