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
| 2835 | * Note that this function takes 'min' and 'max' in the same form of the |
| 2836 | * Redis ZRANGEBYLEX command. */ |
| 2837 | int zsetInitLexRange(RedisModuleKey *key, RedisModuleString *min, RedisModuleString *max, int first) { |
| 2838 | if (!key->value || key->value->type != OBJ_ZSET) return REDISMODULE_ERR; |
| 2839 | |
| 2840 | RM_ZsetRangeStop(key); |
| 2841 | key->u.zset.er = 0; |
| 2842 | |
| 2843 | /* Setup the range structure used by the sorted set core implementation |
| 2844 | * in order to seek at the specified element. */ |
| 2845 | zlexrangespec *zlrs = &key->u.zset.lrs; |
| 2846 | if (zslParseLexRange(min, max, zlrs) == C_ERR) return REDISMODULE_ERR; |
| 2847 | |
| 2848 | /* Set the range type to lex only after successfully parsing the range, |
| 2849 | * otherwise we don't want the zlexrangespec to be freed. */ |
| 2850 | key->u.zset.type = REDISMODULE_ZSET_RANGE_LEX; |
| 2851 | |
| 2852 | if (key->value->encoding == OBJ_ENCODING_ZIPLIST) { |
| 2853 | key->u.zset.current = first ? zzlFirstInLexRange(key->value->ptr,zlrs) : |
| 2854 | zzlLastInLexRange(key->value->ptr,zlrs); |
| 2855 | } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) { |
| 2856 | zset *zs = key->value->ptr; |
| 2857 | zskiplist *zsl = zs->zsl; |
| 2858 | key->u.zset.current = first ? zslFirstInLexRange(zsl,zlrs) : |
| 2859 | zslLastInLexRange(zsl,zlrs); |
| 2860 | } else { |
| 2861 | serverPanic("Unsupported zset encoding"); |
| 2862 | } |
| 2863 | if (key->u.zset.current == NULL) key->u.zset.er = 1; |
| 2864 | |
| 2865 | return REDISMODULE_OK; |
| 2866 | } |
| 2867 | |
| 2868 | /* Setup a sorted set iterator seeking the first element in the specified |
| 2869 | * lexicographical range. Returns REDISMODULE_OK if the iterator was correctly |
no test coverage detected