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