From f31cf249b97d116dc9c0f8c1af3d33f6e3687050 Mon Sep 17 00:00:00 2001 From: antirez Date: Tue, 5 Nov 2013 15:32:21 +0100 Subject: [PATCH] SCAN: when iterating ziplists or intsets always return cursor of 0. The previous implementation assumed that the first call always happens with cursor set to 0, this may not be the case, and we want to return 0 anyway otherwise the (broken) client code will loop forever. --- src/db.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/db.c b/src/db.c index c7de00496..1ed0bb2af 100644 --- a/src/db.c +++ b/src/db.c @@ -462,6 +462,7 @@ void scanGenericCommand(redisClient *c, robj *o) { while(intsetGet(o->ptr,pos++,&ll)) listAddNodeTail(keys,createStringObjectFromLongLong(ll)); + cursor = 0; } else if (o->type == REDIS_HASH || o->type == REDIS_ZSET) { unsigned char *p = ziplistIndex(o->ptr,0); unsigned char *vstr; @@ -475,6 +476,7 @@ void scanGenericCommand(redisClient *c, robj *o) { createStringObjectFromLongLong(vll)); p = ziplistNext(o->ptr,p); } + cursor = 0; } else { redisPanic("Not handled encoding in SCAN."); }