ZRANGESTORE
ZRANGESTORE dst src min max [BYSCORE | BYLEX] [REV] [LIMIT offset count]
- Group
- Sorted set
- Complexity
- O(log(N)+M) where N is the size of the source sorted set and M is the number of members stored
- Arity
- -5 (at least 5 words, counting the command name)
- Flags
- write
- Keys
- first 1, last 2, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZRANGESTORE selects a range from the sorted set at src exactly as
ZRANGE would, and stores it, with scores, as a sorted set
at dst. Whatever dst held before is replaced. If the range is empty, dst
is deleted.
min and max are ranks by default, scores with BYSCORE, or lexicographic
bounds with BYLEX. With REV and BYSCORE or BYLEX, give the higher bound
first.
Options
Section titled “Options”| Option | Effect |
|---|---|
BYSCORE |
Treat min and max as scores (( for exclusive, -inf / +inf allowed). |
BYLEX |
Treat min and max as lexicographic bounds ([, (, -, +). |
REV |
Select from the highest to the lowest. |
LIMIT offset count |
Skip offset matching members, then take at most count. Only with BYSCORE or BYLEX. |
WITHSCORES is not accepted: scores are always stored.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the number of members stored in dst |
Same |
Errors are those of ZRANGE: syntax errors for unknown or
conflicting options (including WITHSCORES), the LIMIT combination error,
bad bounds, and WRONGTYPE if src holds a value that is not a sorted set.
Examples
Section titled “Examples”127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c" 4 "d"(integer) 4127.0.0.1:6379> ZRANGESTORE top2 board 0 1 REV(integer) 2127.0.0.1:6379> ZRANGE top2 0 -1 WITHSCORES1) "c"2) "3"3) "d"4) "4"127.0.0.1:6379> ZRANGESTORE mid board (1 (4 BYSCORE(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.