📅  最后修改于: 2020-12-02 01:07:29             🧑  作者: Mango
Redis Sorted Sets与Redis Sets类似,但是第一个具有存储值的独特功能。这意味着排序集的每个成员都与一个得分相关联,该得分可用于从最小到最大得分采用排序的排序集。
redis 127.0.0.1:6379> ZADD javatpoint 1 redis
(integer) 0
redis 127.0.0.1:6379> ZADD javatpoint 2 cassandra
(integer) 1
redis 127.0.0.1:6379> ZADD javatpoint 3 cassandra
(integer) 0
redis 127.0.0.1:6379> ZADD javatpoint 3 mysql
(integer) 1
redis 127.0.0.1:6379> ZADD javatpoint 4 mysql
(integer) 0
redis 127.0.0.1:6379> ZRANGE javatpoint 0 10 WITHSCORES
1) "redis"
2) "1"
3) "cassandra"
4) "3"
5) "mysql"
6) "4"
以下是排序集中使用的命令列表。
Index | Commands | Description |
---|---|---|
1 | ZADD key score1 member1 [score2 member2] | It is used to add one or more members to a sorted set, or updates its score, if it already exists |
2 | ZCARD key | It is used to get the number of members in a sorted set |
3 | ZCOUNT key min max | It is used to count the members in a sorted set with scores within the given values |
4 | ZINCRBY key increment member | It is used to increment the score of a member in a sorted set |
5 | ZINTERSTORE destination numkeys key [key …] | It is used to intersect multiple sorted sets and stores the resulting sorted set in a new key |
6 | ZLEXCOUNT key min max | It is used to count the number of members in a sorted set between a given lexicographical range |
7 | ZRANGE key start stop [WITHSCORES] | It is used to return a range of members in a sorted set, by index |
8 | ZRANGEBYLEX key min max [LIMIT offset count] | It is used to return a range of members in a sorted set, by lexicographical range |
9 | ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT] | It is used to return a range of members in a sorted set, by score |
10 | ZRANK key member | It is used to determine the index of a member in a sorted set |
11 | ZREM key member [member …] | It is used to remove one or more members from a sorted set |
12 | ZREMRANGEBYLEX key min max | It is used to remove all members in a sorted set between the given lexicographical range |
13 | ZREMRANGEBYRANK key start stop | It is used to remove all members in a sorted set within the given indexes |
14 | ZREMRANGEBYSCORE key min max | It is used to remove all members in a sorted set within the given scores |
15 | ZREVRANGE key start stop [WITHSCORES] | It is used to return a range of members in a sorted set, by index, with scores ordered from high to low |
16 | ZREVRANGEBYSCORE key max min [WITHSCORES] | It is used to return a range of members in a sorted set, by score, with scores ordered from high to low |
17 | ZREVRANK key member | It is used to determine the index of a member in a sorted set, with scores ordered from high to low |
18 | ZSCORE key member | It is used to retrieve the score associated with the given member in a sorted set |
19 | ZUNIONSTORE destination numkeys key [key …] | It is used to add multiple sorted sets and stores the resulting sorted set in a new key |
20 | ZSCAN key cursor [MATCH pattern] [COUNT count] | It is used to incrementally iterates sorted sets elements and associated scores |