zsets_intro
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.
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
| Commands | Version | Syntax | Description |
|---|---|---|---|
| ZADD | 1.2.0 | key score member [score member ...] | Add score and member to the set |
| ZCARD | 1.2.0 | key | Return the number of members in the set |
| ZINCRBY | 1.2.0 | key increment member | Increment or decrement the score by the given amount |
| ZRANGE | 1.2.0 | key start stop [withscores] | Query by index range |
| ZRANGEBYSCORE | 1.2.0 | key min max [withscores] [limit offset count] | Query members in a score range |
| ZREM | 1.2.0 | key member [member ...] | Delete members from the set |
| ZREMRANGEBYSCORE | 1.2.0 | key min max | Delete members by score range |
| ZREVRANGE | 1.2.0 | key start stop [withscores] | Query by index range from highest |
| ZSCORE | 1.2.0 | key member | Return the score of a member |
| ZCOUNT | 2.0.0 | key min max | Count members in a score range |
| ZRANK | 2.0.0 | key member | Return the rank (index) of a member |
| ZREVRANK | 2.0.0 | key member | Return the reverse rank (index) of a member |
| ZREMRANGEBYRANK | 2.0.0 | key start stop | Delete members by index range |
| ZUNIONSTORE | 2.0.0 | dest_key numkeys src_key [src_key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] | Compute the union and store it in a new set |
| ZINTERSTORE | 2.0.0 | dest_key numkeys src_key [src_key ...] [WEIGHTS weight [weight ...]] [AGGREGATE SUM|MIN|MAX] | Compute the intersection and store it in a new set |
| ZREVRANGEBYSCORE | 2.2.0 | key max min [withscores] [limit offset count] | Query by score range from highest |
| ZSCAN | 2.8.0 | key cursor [MATCH pattern] [COUNT count] | Scan scores and members in batches |
| ZRANGEBYLEX | 2.8.9 | key min max [limit offset count] | Query members in a lexicographical range |
| ZLEXCOUNT | 2.8.9 | key min max | Count members in a lexicographical range |
| ZREMRANGEBYLEX | 2.8.9 | key min max | Delete members by lexicographical range |
| ZREVRANGEBYLEX | 2.8.9 | key max min [limit offset count] | Query by lexicographical range from highest |
| ZPOPMIN | 5.0.0 | key | Pop members with the lowest scores |
| ZPOPMAX | 5.0.0 | key | Pop members with the highest scores |
| BZPOPMIN | 5.0.0 | key | Block until data arrives, then pop the lowest scores |
| BZPOPMAX | 5.0.0 | key | Block until data arrives, then pop the highest scores |
| ZMSCORE | 6.2.0 | member [member ...] | Return scores of members - multiple members allowed |
| ZRANDMEMBER | 6.2.0 | key | Return random members |
| ZRANGESTORE | 6.2.0 | dst src start stop | Store the query result in another key |
| ZUNION | 6.2.0 | numkeys key [key ...] | Compute the union |
| ZINTER | 6.2.0 | numkeys key [key ...] | Compute the intersection |
| ZDIFF | 6.2.0 | numkeys key [key ...] | Compute the difference |
| ZDIFFSTORE | 6.2.0 | destination numkeys key [key ...] | Compute the difference and store it in a new set |
| ZISMEMBER | Ent 6.0.0 | key member | Check whether a member exists in the set |
| ZLS | Ent 6.0.0 | key pattern | Query values by pattern |
| ZRM | Ent 6.0.0 | key pattern | Delete values by pattern |
| ZLEN | Ent 7.0.0 | key | Return the number of members in the key |
Total : 36
Redis Internal : Sorted Set internal data structure
Sorted Set data structure
-
SKIP LIST: once you understand the skip list, the main data structure of Sorted Set,
- you will understand how ZADD works,
- and how ZRANGE can query millions of items so quickly.
- Many remaining questions about Sorted Set will also be answered.
- ZIP LIST
- the background of ziplist, its data structure and basic operations,
- and how much performance and memory it saves when used in Sorted Set.
PDF manual
| << SSCAN | SORTED SETS Introduction | ZADD >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
