Don't decode object on STRLEN when not necessary

This commit is contained in:
Pieter Noordhuis 2010-12-14 10:31:11 +01:00
parent cc20906390
commit 7ecd4644e7

View 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");
}
}