简介
- Redis Sorted Set / Zset(有序集合)
- 命令特征:所有命令开始前都带有字母“Z”
增加
| 命令 | 解释 |
| —- | —- |
| ZADD key [NX|XX] [CH] [INCR] score member [score member …] | 添加到有序set的一个或多个成员,或更新的分数,如果它已经存在 |
| ZINCRBY key increment member | 增量的一名成员在排序设置的评分 |
删除
命令 |
解释 |
ZREMRANGEBYLEX key min max |
删除名称按字典由低到高排序成员之间所有成员。 |
ZREMRANGEBYRANK key start stop |
在排序设置的所有成员在给定的索引中删除 |
ZREMRANGEBYSCORE key min max |
删除一个排序的设置在给定的分数所有成员 |
查询
命令 |
解释 |
ZCARD key |
获取一个排序的集合中的成员数量 |
ZCOUNT key min max |
返回分数范围内的成员数量 |
ZLEXCOUNT key min max |
返回成员之间的成员数量 |
ZRANGE key start stop [WITHSCORES] |
根据指定的index返回,返回sorted set的成员列表 |
修改
命令 |
解释 |
ZSCAN key cursor [MATCH pattern] [COUNT count] |
迭代sorted sets里面的元素 |
其他
http://www.redis.cn/commands.html#sorted_set
ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
summary: Add one or more members to a sorted set, or update its score if it already exists
since: 1.2.0
ZCARD key
summary: Get the number of members in a sorted set
since: 1.2.0
ZCOUNT key min max
summary: Count the members in a sorted set with scores within the given values
since: 2.0.0
ZINCRBY key increment member
summary: Increment the score of a member in a sorted set
since: 1.2.0
ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0
ZLEXCOUNT key min max
summary: Count the number of members in a sorted set between a given lexicographical range
since: 2.8.9
ZRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index
since: 1.2.0
ZRANGEBYLEX key min max [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range
since: 2.8.9
ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score
since: 1.0.5
ZRANK key member
summary: Determine the index of a member in a sorted set
since: 2.0.0
ZREM key member [member ...]
summary: Remove one or more members from a sorted set
since: 1.2.0
ZREMRANGEBYLEX key min max
summary: Remove all members in a sorted set between the given lexicographical range
since: 2.8.9
ZREMRANGEBYRANK key start stop
summary: Remove all members in a sorted set within the given indexes
since: 2.0.0
ZREMRANGEBYSCORE key min max
summary: Remove all members in a sorted set within the given scores
since: 1.2.0
ZREVRANGE key start stop [WITHSCORES]
summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
since: 1.2.0
ZREVRANGEBYLEX key max min [LIMIT offset count]
summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
since: 2.8.9
ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
since: 2.2.0
ZREVRANK key member
summary: Determine the index of a member in a sorted set, with scores ordered from high to low
since: 2.0.0
ZSCAN key cursor [MATCH pattern] [COUNT count]
summary: Incrementally iterate sorted sets elements and associated scores
since: 2.8.0
ZSCORE key member
summary: Get the score associated with the given member in a sorted set
since: 1.2.0
ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
summary: Add multiple sorted sets and store the resulting sorted set in a new key
since: 2.0.0