Modules: put zset iterator current element in auto memory pool.

This commit is contained in:
antirez 2016-04-19 17:12:48 +02:00
parent 6eeeda39e9
commit bdbb5a0253

View File

@ -1051,6 +1051,8 @@ int RM_ZsetFirstInRange(RedisModuleKey *key, RedisModuleZsetRange *zr) {
* or NULL if the range specified in the iterator does not include any * or NULL if the range specified in the iterator does not include any
* element. */ * element. */
RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score) { RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score) {
RedisModuleString *str;
if (key->zcurrent == NULL) return NULL; if (key->zcurrent == NULL) return NULL;
if (key->value->encoding == OBJ_ENCODING_ZIPLIST) { if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
unsigned char *eptr, *sptr; unsigned char *eptr, *sptr;
@ -1060,14 +1062,16 @@ RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score
sptr = ziplistNext(key->value->ptr,eptr); sptr = ziplistNext(key->value->ptr,eptr);
*score = zzlGetScore(sptr); *score = zzlGetScore(sptr);
} }
return createObject(OBJ_STRING,ele); str = createObject(OBJ_STRING,ele);
} else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) { } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
zskiplistNode *ln = key->zcurrent; zskiplistNode *ln = key->zcurrent;
if (score) *score = ln->score; if (score) *score = ln->score;
return createStringObject(ln->ele,sdslen(ln->ele)); str = createStringObject(ln->ele,sdslen(ln->ele));
} else { } else {
serverPanic("Unsupported zset encoding"); serverPanic("Unsupported zset encoding");
} }
RM_AutoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,str);
return str;
} }
/* Go to the next element of the sorted set iterator. Returns 1 if there was /* Go to the next element of the sorted set iterator. Returns 1 if there was