]> git.saurik.com Git - redis.git/commitdiff
fixed LINDEX to always return bulk response
authorPieter Noordhuis <pcnoordhuis@gmail.com>
Sun, 30 May 2010 01:08:24 +0000 (03:08 +0200)
committerPieter Noordhuis <pcnoordhuis@gmail.com>
Sun, 30 May 2010 01:25:04 +0000 (03:25 +0200)
redis.c

diff --git a/redis.c b/redis.c
index 064f4cad9f18d61dff0fd858128f936167142713..1ae32797186e3b4319c85c552be19349d56a1505 100644 (file)
--- a/redis.c
+++ b/redis.c
@@ -4993,6 +4993,7 @@ static void lindexCommand(redisClient *c) {
     robj *o = lookupKeyReadOrReply(c,c->argv[1],shared.nullbulk);
     if (o == NULL || checkType(c,o,REDIS_LIST)) return;
     int index = atoi(c->argv[2]->ptr);
+    robj *value = NULL;
 
     if (o->encoding == REDIS_ENCODING_ZIPLIST) {
         unsigned char *p;
@@ -5002,17 +5003,20 @@ static void lindexCommand(redisClient *c) {
         p = ziplistIndex(o->ptr,index);
         if (ziplistGet(p,&v,&vlen,&vval)) {
             if (v) {
-                addReplySds(c,sdsnewlen(v,vlen));
+                value = createStringObject(v,vlen);
             } else {
-                addReplyLongLong(c,vval);
+                value = createStringObjectFromLongLong(vval);
             }
+            addReplyBulk(c,value);
+            decrRefCount(value);
         } else {
             addReply(c,shared.nullbulk);
         }
     } else if (o->encoding == REDIS_ENCODING_LIST) {
         listNode *ln = listIndex(o->ptr,index);
         if (ln != NULL) {
-            addReply(c,(robj*)listNodeValue(ln));
+            value = listNodeValue(ln);
+            addReplyBulk(c,value);
         } else {
             addReply(c,shared.nullbulk);
         }