Redis Sorted Sets

Redis Sorted Sets are similar to Redis Sets but the first one has the unique feature of values stored. It means every member of a Sorted Set is associated with a score which can be used to take the sorted set ordered, from the smallest to the greatest score.

Example

Redis Sorted Sets 1

Redis Sorted Sets Commands

Following is a list of commands used in sorted sets.

IndexCommandsDescription
1ZADD 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
2ZCARD keyIt is used to get the number of members in a sorted set
3ZCOUNT key min maxIt is used to count the members in a sorted set with scores within the given values
4ZINCRBY key increment memberIt is used to increment the score of a member in a sorted set
5ZINTERSTORE destination numkeys key [key ...]It is used to intersect multiple sorted sets and stores the resulting sorted set in a new key
6ZLEXCOUNT key min maxIt is used to count the number of members in a sorted set between a given lexicographical range
7ZRANGE key start stop [WITHSCORES]It is used to return a range of members in a sorted set, by index
8ZRANGEBYLEX key min max [LIMIT offset count]It is used to return a range of members in a sorted set, by lexicographical range
9ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT]It is used to return a range of members in a sorted set, by score
10ZRANK key memberIt is used to determine the index of a member in a sorted set
11ZREM key member [member ...]It is used to remove one or more members from a sorted set
12ZREMRANGEBYLEX key min maxIt is used to remove all members in a sorted set between the given lexicographical range
13ZREMRANGEBYRANK key start stopIt is used to remove all members in a sorted set within the given indexes
14ZREMRANGEBYSCORE key min maxIt is used to remove all members in a sorted set within the given scores
15ZREVRANGE 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
16ZREVRANGEBYSCORE 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
17ZREVRANK key memberIt is used to determine the index of a member in a sorted set, with scores ordered from high to low
18ZSCORE key memberIt is used to retrieve the score associated with the given member in a sorted set
19ZUNIONSTORE destination numkeys key [key ...]It is used to add multiple sorted sets and stores the resulting sorted set in a new key
20ZSCAN key cursor [MATCH pattern] [COUNT count]It is used to incrementally iterates sorted sets elements and associated scores





Latest Courses