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. */
| 2979 | * or NULL if the range specified in the iterator does not include any |
| 2980 | * element. */ |
| 2981 | RedisModuleString *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 |
nothing calls this directly
no test coverage detected