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

Function zsetInitLexRange

app/redis-6.2.6/src/module.c:2837–2866  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

2835 * Note that this function takes 'min' and 'max' in the same form of the
2836 * Redis ZRANGEBYLEX command. */
2837int 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

Callers 2

RM_ZsetFirstInLexRangeFunction · 0.85
RM_ZsetLastInLexRangeFunction · 0.85

Calls 6

RM_ZsetRangeStopFunction · 0.85
zslParseLexRangeFunction · 0.85
zzlFirstInLexRangeFunction · 0.85
zzlLastInLexRangeFunction · 0.85
zslFirstInLexRangeFunction · 0.85
zslLastInLexRangeFunction · 0.85

Tested by

no test coverage detected