ZLEXCOUNT
ZLEXCOUNT key min max
- Group
- Sorted set
- Complexity
- O(log(N)) where N is the size of the sorted set
- Arity
- 4 (exactly, counting the command name)
- Flags
- read-only, fast
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZLEXCOUNT returns how many members of the sorted set at key fall between
min and max in byte-wise lexicographic order. It is meant for sorted sets
where every member has the same score; with mixed scores the result is not
meaningful.
Each bound must start with [ (inclusive) or ( (exclusive), followed by the
value, or be - (lowest possible) or + (highest possible).
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the number of members in the range | Same |
| Key does not exist | Integer 0 |
Same |
Errors:
ERR min or max not valid string range itemif a bound has the wrong form. The bounds are checked before the key is looked up.WRONGTYPEifkeyholds a value that is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD names 0 "ann" 0 "bob" 0 "cat" 0 "dan"(integer) 4127.0.0.1:6379> ZLEXCOUNT names - +(integer) 4127.0.0.1:6379> ZLEXCOUNT names [b (d(integer) 2Compatibility
Section titled “Compatibility”Same as Redis 7.4 and Valkey 8.
See also
Section titled “See also”Was this page helpful?
Thanks for the feedback.