简介

  • 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

  1. ZADD key [NX|XX] [CH] [INCR] score member [score member ...]
  2. summary: Add one or more members to a sorted set, or update its score if it already exists
  3. since: 1.2.0
  4. ZCARD key
  5. summary: Get the number of members in a sorted set
  6. since: 1.2.0
  7. ZCOUNT key min max
  8. summary: Count the members in a sorted set with scores within the given values
  9. since: 2.0.0
  10. ZINCRBY key increment member
  11. summary: Increment the score of a member in a sorted set
  12. since: 1.2.0
  13. ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  14. summary: Intersect multiple sorted sets and store the resulting sorted set in a new key
  15. since: 2.0.0
  16. ZLEXCOUNT key min max
  17. summary: Count the number of members in a sorted set between a given lexicographical range
  18. since: 2.8.9
  19. ZRANGE key start stop [WITHSCORES]
  20. summary: Return a range of members in a sorted set, by index
  21. since: 1.2.0
  22. ZRANGEBYLEX key min max [LIMIT offset count]
  23. summary: Return a range of members in a sorted set, by lexicographical range
  24. since: 2.8.9
  25. ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
  26. summary: Return a range of members in a sorted set, by score
  27. since: 1.0.5
  28. ZRANK key member
  29. summary: Determine the index of a member in a sorted set
  30. since: 2.0.0
  31. ZREM key member [member ...]
  32. summary: Remove one or more members from a sorted set
  33. since: 1.2.0
  34. ZREMRANGEBYLEX key min max
  35. summary: Remove all members in a sorted set between the given lexicographical range
  36. since: 2.8.9
  37. ZREMRANGEBYRANK key start stop
  38. summary: Remove all members in a sorted set within the given indexes
  39. since: 2.0.0
  40. ZREMRANGEBYSCORE key min max
  41. summary: Remove all members in a sorted set within the given scores
  42. since: 1.2.0
  43. ZREVRANGE key start stop [WITHSCORES]
  44. summary: Return a range of members in a sorted set, by index, with scores ordered from high to low
  45. since: 1.2.0
  46. ZREVRANGEBYLEX key max min [LIMIT offset count]
  47. summary: Return a range of members in a sorted set, by lexicographical range, ordered from higher to lower strings.
  48. since: 2.8.9
  49. ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
  50. summary: Return a range of members in a sorted set, by score, with scores ordered from high to low
  51. since: 2.2.0
  52. ZREVRANK key member
  53. summary: Determine the index of a member in a sorted set, with scores ordered from high to low
  54. since: 2.0.0
  55. ZSCAN key cursor [MATCH pattern] [COUNT count]
  56. summary: Incrementally iterate sorted sets elements and associated scores
  57. since: 2.8.0
  58. ZSCORE key member
  59. summary: Get the score associated with the given member in a sorted set
  60. since: 1.2.0
  61. ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight] [AGGREGATE SUM|MIN|MAX]
  62. summary: Add multiple sorted sets and store the resulting sorted set in a new key
  63. since: 2.0.0