Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Redis Zremrangebyrank command

Redis Zremrangebyrank command

Redis Sorted Set

The Redis Zremrangebyrank command is used to remove all members within a specified rank range of a sorted set.

Syntax

The basic syntax of the redis Zremrangebyrank command is as follows:



redis 127.0.0.1:6379> ZREMRANGEBYRANK key start stop

Available Version

= 2.0.0

Return Value

The number of members removed.

Example



redis 127.0.0.1:6379> ZADD salary 2000 jack

(integer) 1

redis 127.0.0.1:6379> ZADD salary 5000 tom

(integer) 1

redis 127.0.0.1:6379> ZADD salary 3500 peter

(integer) 1



redis 127.0.0.1:6379> ZREMRANGEBYRANK salary 0 1       # 移除下标 0 至 1 区间内的成员

(integer) 2



redis 127.0.0.1:6379> ZRANGE salary 0 -1 WITHSCORES    # 有序集只剩下一个成员

1) "tom"

2) "5000"

Redis Sorted Set