Redis Sorted Sets: ZREMRANGEBYRANK
ZREMRANGEBYRANK key start stop
Redis ZREMRANGEBYRANK command is used to remove all elements in the sorted set stored at the key with the rank between start and stop.
Both start and stop are zero-based indexes,
- 0 is the first element,
- 1 is the next element and so on.
They can also be negative numbers indicating offsets starting at the element with the highest score.
- -1 being the last element of the sorted set
- -2 the penultimate element and so on.
Syntax:
ZREMRANGEBYRANK key start stop
Available since
2.0.0.
Return Value
Integer reply, the number of elements removed.
Return Value Type
Integer
Example: Redis ZREMRANGEBYRANK: Deleting a member to the index range
127.0.0.1:6379> ZADD mycityset 1 Delhi 2 Mumbai 3 Hyderabad 4 Kolkata 5 Chennai (integer) 5 127.0.0.1:6379> ZRANGE mycityset 0 -1 WITHSCORES 1) "Delhi" 2) "1" 3) "Mumbai" 4) "2" 5) "Hyderabad" 6) "3" 7) "Kolkata" 8) "4" 9) "Chennai" 10) "5" 127.0.0.1:6379> ZREMRANGEBYRANK mycityset 1 2 (integer) 2 127.0.0.1:6379> ZRANGE mycityset 0 -1 WITHSCORES 1) "Delhi" 2) "1" 3) "Kolkata" 4) "4" 5) "Chennai" 6) "5"
Example: Redis ZREMRANGEBYRANK: Deleting a member using a negative index
127.0.0.1:6379> ZADD mycityset 1 Delhi 2 Mumbai 3 Hyderabad 4 Kolkata 5 Chennai (integer) 5 127.0.0.1:6379> ZRANGE mycityset 0 -1 WITHSCORES 1) "Delhi" 2) "1" 3) "Mumbai" 4) "2" 5) "Hyderabad" 6) "3" 7) "Kolkata" 8) "4" 9) "Chennai" 10) "5" 127.0.0.1:6379> ZREMRANGEBYRANK mycityset -3 -2 (integer) 2 127.0.0.1:6379> ZRANGE mycityset 0 -1 WITHSCORES 1) "Delhi" 2) "1" 3) "Mumbai" 4) "2" 5) "Chennai" 6) "5"
Previous:
ZREMRANGEBYLEX
Next:
ZREMRANGEBYSCORE
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics