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

Function zsetInitScoreRange

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

Helper function for RM_ZsetFirstInScoreRange() and RM_ZsetLastInScoreRange(). * Setup the sorted set iteration according to the specified score 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. */

Source from the content-addressed store, hash-verified

2771 * otherwise the last. Return REDISMODULE_OK on success otherwise
2772 * REDISMODULE_ERR. */
2773int zsetInitScoreRange(RedisModuleKey *key, double min, double max, int minex, int maxex, int first) {
2774 if (!key->value || key->value->type != OBJ_ZSET) return REDISMODULE_ERR;
2775
2776 RM_ZsetRangeStop(key);
2777 key->u.zset.type = REDISMODULE_ZSET_RANGE_SCORE;
2778 key->u.zset.er = 0;
2779
2780 /* Setup the range structure used by the sorted set core implementation
2781 * in order to seek at the specified element. */
2782 zrangespec *zrs = &key->u.zset.rs;
2783 zrs->min = min;
2784 zrs->max = max;
2785 zrs->minex = minex;
2786 zrs->maxex = maxex;
2787
2788 if (key->value->encoding == OBJ_ENCODING_ZIPLIST) {
2789 key->u.zset.current = first ? zzlFirstInRange(key->value->ptr,zrs) :
2790 zzlLastInRange(key->value->ptr,zrs);
2791 } else if (key->value->encoding == OBJ_ENCODING_SKIPLIST) {
2792 zset *zs = key->value->ptr;
2793 zskiplist *zsl = zs->zsl;
2794 key->u.zset.current = first ? zslFirstInRange(zsl,zrs) :
2795 zslLastInRange(zsl,zrs);
2796 } else {
2797 serverPanic("Unsupported zset encoding");
2798 }
2799 if (key->u.zset.current == NULL) key->u.zset.er = 1;
2800 return REDISMODULE_OK;
2801}
2802
2803/* Setup a sorted set iterator seeking the first element in the specified
2804 * range. Returns REDISMODULE_OK if the iterator was correctly initialized

Callers 2

RM_ZsetFirstInScoreRangeFunction · 0.85
RM_ZsetLastInScoreRangeFunction · 0.85

Calls 5

RM_ZsetRangeStopFunction · 0.85
zzlFirstInRangeFunction · 0.85
zzlLastInRangeFunction · 0.85
zslFirstInRangeFunction · 0.85
zslLastInRangeFunction · 0.85

Tested by

no test coverage detected