Skip to content

Ask the HotKV docs

Answers come only from these docs and can be wrong; check the linked pages before you rely on them.

ZREMRANGEBYRANK

Last updated
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.

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 range if start or stop is not an integer. This is checked before the key is looked up.
  • WRONGTYPE if key holds a value that is not a sorted set.
127.0.0.1:6379> ZADD board 1 "a" 2 "b" 3 "c" 4 "d"
(integer) 4
127.0.0.1:6379> ZREMRANGEBYRANK board 0 -3
(integer) 2
127.0.0.1:6379> ZRANGE board 0 -1
1) "c"
2) "d"

Same as Redis 7.4 and Valkey 8.

ZREMRANGEBYSCORE, ZREMRANGEBYLEX, ZRANGE, ZRANK