MCPcopy Create free account
hub / github.com/F-Stack/f-stack / RM_ZsetRangeCurrentElement

Function RM_ZsetRangeCurrentElement

app/redis-6.2.6/src/module.c:2893–2916  ·  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

2891 * or NULL if the range specified in the iterator does not include any
2892 * element. */
2893RedisModuleString *RM_ZsetRangeCurrentElement(RedisModuleKey *key, double *score) {
2894 RedisModuleString *str;
2895
2896 if (!key->value || key->value->type != OBJ_ZSET) return NULL;
2897 if (key->u.zset.current == NULL) return NULL;
2898 if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
2899 unsigned char *eptr, *sptr;
2900 eptr = key->u.zset.current;
2901 sds ele = ziplistGetObject(eptr);
2902 if (score) {
2903 sptr = ziplistNext(key->value->ptr,eptr);
2904 *score = zzlGetScore(sptr);
2905 }
2906 str = createObject(OBJ_STRING,ele);
2907 } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
2908 zskiplistNode *ln = key->u.zset.current;
2909 if (score) *score = ln->score;
2910 str = createStringObject(ln->ele,sdslen(ln->ele));
2911 } else {
2912 serverPanic("Unsupported zset encoding");
2913 }
2914 autoMemoryAdd(key->ctx,REDISMODULE_AM_STRING,str);
2915 return str;
2916}
2917
2918/* Go to the next element of the sorted set iterator. Returns 1 if there was
2919 * a next element, 0 if we are already at the latest element or the range

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected