Helper function for RM_ZsetFirstInLexRange() and RM_ZsetLastInLexRange(). * Setup the sorted set iteration according to the specified lexicographical * range (see the functions calling it for more info). If 'first' is true the * first element in the range is used as a starting point for the iterator * otherwise the last. Return REDISMODULE_OK on success otherwise * REDISMODULE_ERR. * * Note
| 2923 | * Note that this function takes 'min' and 'max' in the same form of the |
| 2924 | * Redis ZRANGEBYLEX command. */ |
| 2925 | int zsetInitLexRange(RedisModuleKey *key, RedisModuleString *min, RedisModuleString *max, int first) { |
| 2926 | if (!key->value || key->value->type != OBJ_ZSET) return REDISMODULE_ERR; |
| 2927 | |
| 2928 | RM_ZsetRangeStop(key); |
| 2929 | key->u.zset.er = 0; |
| 2930 | |
| 2931 | /* Setup the range structure used by the sorted set core implementation |
| 2932 | * in order to seek at the specified element. */ |
| 2933 | zlexrangespec *zlrs = &key->u.zset.lrs; |
| 2934 | if (zslParseLexRange(min, max, zlrs) == C_ERR) return REDISMODULE_ERR; |
| 2935 | |
| 2936 | /* Set the range type to lex only after successfully parsing the range, |
| 2937 | * otherwise we don't want the zlexrangespec to be freed. */ |
| 2938 | key->u.zset.type = REDISMODULE_ZSET_RANGE_LEX; |
| 2939 | |
| 2940 | if (key->value->encoding == OBJ_ENCODING_ZIPLIST) { |
| 2941 | key->u.zset.current = first ? zzlFirstInLexRange((unsigned char*)ptrFromObj(key->value),zlrs) : |
| 2942 | zzlLastInLexRange((unsigned char*)ptrFromObj(key->value),zlrs); |
| 2943 | } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) { |
| 2944 | zset *zs = (zset*)ptrFromObj(key->value); |
| 2945 | zskiplist *zsl = zs->zsl; |
| 2946 | key->u.zset.current = first ? zslFirstInLexRange(zsl,zlrs) : |
| 2947 | zslLastInLexRange(zsl,zlrs); |
| 2948 | } else { |
| 2949 | serverPanic("Unsupported zset encoding"); |
| 2950 | } |
| 2951 | if (key->u.zset.current == NULL) key->u.zset.er = 1; |
| 2952 | |
| 2953 | return REDISMODULE_OK; |
| 2954 | } |
| 2955 | |
| 2956 | /* Setup a sorted set iterator seeking the first element in the specified |
| 2957 | * lexicographical range. Returns REDISMODULE_OK if the iterator was correctly |
no test coverage detected