ZREMRANGEBYRANK
ZREMRANGEBYRANK key start stop
- Group
- Sorted set
- Complexity
- O(log(N)+M) where N is the size of the sorted set and M is the number of members removed
- Arity
- 4 (exactly, counting the command name)
- Flags
- write
- Keys
- first 1, last 1, step 1
- HotKV Cloud
- All plans
- On-Premise
- no license needed
ZREMRANGEBYRANK removes the members of the sorted set at key whose rank
(position from the lowest score, starting at 0) is between start and
stop, both included. Negative ranks count from the highest score: -1 is the
highest-scored member. When the sorted set becomes empty, the key is deleted.
For example, ZREMRANGEBYRANK key 0 -11 keeps only the 10 highest-scored
members.
Return value
Section titled “Return value”| Case | RESP2 | RESP3 |
|---|---|---|
| Success | Integer: the number of members removed | Same |
| Key does not exist | Integer 0 |
Same |
Errors:
ERR value is not an integer or out of rangeifstartorstopis not an integer. This is 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 board 1 "a" 2 "b" 3 "c" 4 "d"(integer) 4127.0.0.1:6379> ZREMRANGEBYRANK board 0 -3(integer) 2127.0.0.1:6379> ZRANGE board 0 -11) "c"2) "d"Compatibility
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.