MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / RM_ZsetRangeCurrentElement

Function RM_ZsetRangeCurrentElement

src/module.cpp:2981–3004  ·  view source on GitHub ↗

Return the current sorted set element of an active sorted set iterator * or NULL if the range specified in the iterator does not include any * element. */

Source from the content-addressed store, hash-verified

2979 * or NULL if the range specified in the iterator does not include any
2980 * element. */
2981RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score) {
2982 RedisModuleString *str;
2983
2984 if (!key->value || key->value->type != OBJ_ZSET) return NULL;
2985 if (key->u.zset.current == NULL) return NULL;
2986 if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
2987 unsigned char *eptr, *sptr;
2988 eptr = (unsigned char*)key->u.zset.current;
2989 sds ele = ziplistGetObject(eptr);
2990 if (score) {
2991 sptr = ziplistNext((unsigned char*)ptrFromObj(key->value),eptr);
2992 *score = zzlGetScore(sptr);
2993 }
2994 str = createObject(OBJ_STRING,ele);
2995 } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
2996 zskiplistNode *ln = (zskiplistNode*)key->u.zset.current;
2997 if (score) *score = ln->score;
2998 str = createStringObject(ln->ele,sdslen(ln->ele));
2999 } else {
3000 serverPanic("Unsupported zset encoding");
3001 }
3002 autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,str);
3003 return str;
3004}
3005
3006/* Go to the next element of the sorted set iterator. Returns 1 if there was
3007 * a next element, 0 if we are already at the latest element or the range

Callers

nothing calls this directly

Calls 8

ziplistGetObjectFunction · 0.85
ziplistNextFunction · 0.85
ptrFromObjFunction · 0.85
zzlGetScoreFunction · 0.85
createObjectFunction · 0.85
sdslenFunction · 0.85
autoMemoryAddFunction · 0.85
createStringObjectFunction · 0.70

Tested by

no test coverage detected