1
0
mirror of https://github.com/fluencelabs/redis synced 2025-03-29 22:01:03 +00:00

fixed LINDEX to always return bulk response

This commit is contained in:
Pieter Noordhuis 2010-05-30 03:08:24 +02:00
parent dbaa41c618
commit bd8db0ada8

10
redis.c

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