sort
SORT use zset
Apply for Redis Developer Course
|
Redis Regular Inspection / Technical Support
|
Redis Enterprise Server
|
|---|
Sort zset data
Example
| Command> | zadd myzipurl 1 Google.com 2 Facebook.com 3 Youtube.com 4 Yahoo.com 5 Baidu.com |
| Result> | 5 |
| Command> | sort myzipurl alpha sort by member |
| Result> |
0) Baidu.com 1) Facebook.com 2) Google.com 3) Yahoo.com 4) Youtube.com |
| Command> | sort myzipurl by score alpha sort by score |
| Result> |
0) Google.com 1) Facebook.com 2) Youtube.com 3) Yahoo.com 4) Baidu.com |
Join zset with by score and string key
In a zset, if you do not specify BY, it sorts by member. If you specify by score, it sorts by score.
Example
| Command> | sort myzipurl by score get # get pv-* alpha |
| Result> |
0) Google.com 1) 19.60 2) Facebook.com 3) 11.62 4) Youtube.com 5) 4.58 6) Yahoo.com 7) 7.44 8) Baidu.com 9) 8.87 |
Join zset and hash key
Example
| Command> | sort myzipurl by score get # get url-*->pv alpha |
| Result> |
0) Google.com 1) 19.60 2) Facebook.com 3) 11.62 4) Youtube.com 5) 4.58 6) Yahoo.com 7) 7.44 8) Baidu.com 9) 8.87 |
Syntax
SORT key [BY pattern] [LIMIT offset count] [GET pattern [GET pattern ...]] [ASC|DESC] [ALPHA] [STORE destination]
- Available since version 1.0.0.
- Time complexity is O(N+M*log(M)).
| Related commands | SCAN |
| << SORT list | SORT zset | RENAME >> |
|---|
Email
답글이 올라오면 이메일로 알려드리겠습니다.
