SORTED SETS Introduction

Apply for Redis Developer Course Redis Regular Inspection / Technical Support Redis Enterprise Server

Introduction

A Sorted Set has one key with multiple scores and values.
Values are sorted by score and are unique.
If scores are equal, values are sorted lexicographically.
In Sorted Sets, a value is called a member.
Sorted Sets are mainly used when sorting is needed.

Command summary

  • SET: ZADD
  • GET: ZRANGE, ZRANGEBYSCORE, ZRANGEBYLEX, ZREVRANGE, ZREVRANGEBYSCORE, ZREVRANGEBYLEX, ZRANK, ZREVRANK, ZSCORE, ZCARD, ZCOUNT, ZLEXCOUNT, ZSCAN
  • POP: ZPOPMIN, ZPOPMAX
  • REM: ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZREMRANGEBYLEX
  • INCR: ZINCRBY
  • Set operations: ZUNIONSTORE, ZINTERSTORE
  • Enterprise: ZISMEMBER, ZLS, ZRM, SLEN

Sorted Sets command list

CommandsVersionSyntaxDescription
ZADD1.2.0key score member [score member ...]Add score and member to the set
ZCARD1.2.0keyReturn the number of members in the set
ZINCRBY1.2.0key increment memberIncrement or decrement the score by the given amount
ZRANGE1.2.0key start stop [withscores]Query by index range
ZRANGEBYSCORE1.2.0key min max [withscores]
[limit offset count]
Query members in a score range
ZREM1.2.0key member [member ...]Delete members from the set
ZREMRANGEBYSCORE1.2.0key min maxDelete members by score range
ZREVRANGE1.2.0key start stop [withscores]Query by index range from highest
ZSCORE1.2.0key memberReturn the score of a member
ZCOUNT2.0.0key min maxCount members in a score range
ZRANK2.0.0key memberReturn the rank (index) of a member
ZREVRANK2.0.0key memberReturn the reverse rank (index) of a member
ZREMRANGEBYRANK2.0.0key start stopDelete members by index range
ZUNIONSTORE2.0.0dest_key numkeys src_key [src_key ...]
[WEIGHTS weight [weight ...]]
[AGGREGATE SUM|MIN|MAX]
Compute the union and store it in a new set
ZINTERSTORE2.0.0dest_key numkeys src_key [src_key ...]
[WEIGHTS weight [weight ...]]
[AGGREGATE SUM|MIN|MAX]
Compute the intersection and store it in a new set
ZREVRANGEBYSCORE2.2.0key max min [withscores]
[limit offset count]
Query by score range from highest
ZSCAN2.8.0key cursor [MATCH pattern]
[COUNT count]
Scan scores and members in batches
ZRANGEBYLEX2.8.9key min max [limit offset count]Query members in a lexicographical range
ZLEXCOUNT2.8.9key min maxCount members in a lexicographical range
ZREMRANGEBYLEX2.8.9key min maxDelete members by lexicographical range
ZREVRANGEBYLEX2.8.9key max min [limit offset count]Query by lexicographical range from highest
ZPOPMIN5.0.0keyPop members with the lowest scores
ZPOPMAX5.0.0keyPop members with the highest scores
BZPOPMIN5.0.0keyBlock until data arrives, then pop the lowest scores
BZPOPMAX5.0.0keyBlock until data arrives, then pop the highest scores
ZMSCORE 6.2.0member [member ...]Return scores of members - multiple members allowed
ZRANDMEMBER6.2.0keyReturn random members
ZRANGESTORE6.2.0dst src start stopStore the query result in another key
ZUNION6.2.0numkeys key [key ...]Compute the union
ZINTER6.2.0numkeys key [key ...]Compute the intersection
ZDIFF6.2.0numkeys key [key ...]Compute the difference
ZDIFFSTORE6.2.0destination numkeys key [key ...]Compute the difference and store it in a new set
ZISMEMBER Ent 6.0.0key member Check whether a member exists in the set
ZLS Ent 6.0.0key pattern Query values by pattern
ZRM Ent 6.0.0key pattern Delete values by pattern
ZLEN Ent 7.0.0key Return the number of members in the key

Total : 36


Redis Internal : Sorted Set internal data structure

Sorted Set data structure


PDF manual


<< SSCAN SORTED SETS Introduction ZADD >>

Email 답글이 올라오면 이메일로 알려드리겠습니다.