Redis 有序集合(zset)

Redis zremrangebyscore 命令用于删除排序集中存储在 key 处且分数介于最小值和最大值之间的所有元素。

min, max 在分数范围内。要删除所有使用 -inf, + inf。

语法

zremrangebyscore key min max 

可用版本

>=2.2.0.

返回值

整数,移除的元素个数。

返回值类型

整数

示例:Redis zremrangebyscore

127.0.0.1:6379> zadd mycityset 80 北京 60 上海 70 广州 50 深圳 65 武汉
(integer) 5
127.0.0.1:6379> zrangebyscore mycityset -inf +inf  WITHSCORES
 1) "深圳"
 2) "50"
 3) "上海"
 4) "60"
 5) "武汉"
 6) "65"
 7) "广州"
 8) "70"
 9) "北京"
10) "80"
127.0.0.1:6379> zremrangebyscore mycityset -inf (70
(integer) 3
127.0.0.1:6379> zrangebyscore mycityset -inf +inf  WITHSCORES
1) "广州"
2) "70"
3) "北京"
4) "80"
127.0.0.1:6379> zremrangebyscore mycityset -inf 70
(integer) 1
127.0.0.1:6379> zrangebyscore mycityset -inf +inf  WITHSCORES
1) "北京"
2) "80"