Redis ZREMRANGEBYSCORE令

1年前 (2024-04-27)
Redis ZREMRANGEBYSCORE 令移除有序集 key 中,所有 score 值介于 min 和 max 之间(包括等于 min 或 max )的成员。

注意:自版本 2.1.6 开始,score 值等于 min 或 max 的成员也可以不包括在内,详情请参见 ZRANGEBYSCORE 令。

可用版本

ZREMRANGEBYSCORE 令可用版本:>= 2.0.0

语法

Redis ZREMRANGEBYSCORE 令的基本语法如下:

ZREMRANGEBYSCORE key min max 

返回值

被移除成员的数量。

令演示

127.0.0.1:6379> ZADD salary 3000 jack 3500 helen 2880 john 4000 simith 6000 ros

(integer) 5

127.0.0.1:6379> ZRANGE salary 0 -1 withscores #显示所有成员与score值

1) "john"

2) "2880"

3) "jack"

4) "3000"

5) "helen"

6) "3500"

7) "simith"

8) "4000"

9) "ros"

10) "6000"

127.0.0.1:6379> ZREMRANGEBYSCORE salary 4000 6000 #移除4000<=salary<=6000

(integer) 2

127.0.0.1:6379> ZRANGE salary 0 -1 withscores #查询剩余元素

1) "john"

2) "2880"

3) "jack"

4) "3000"

5) "helen"

6) "3500"