SORT use list

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

Sort list data

Example

Command>lpush mylisturl Google.com Facebook.com Youtube.com Yahoo.com Baidu.com
Result>5
Command>sort mylisturl alpha
Result> 0) Baidu.com
1) Facebook.com
2) Google.com
3) Yahoo.com
4) Youtube.com
Command>sort mylisturl alpha desc
Result> 0) Youtube.com
1) Yahoo.com
2) Google.com
3) Facebook.com
4) Baidu.com


Join list and string key with get

Example

Command>sort mylisturl get # get pv-* alpha
Result> 0) Baidu.com
1) 8.87
2) Facebook.com
3) 11.62
4) Google.com
5) 19.60
6) Yahoo.com
7) 7.44
8) Youtube.com
9) 4.58


Join list and string key with order

Example

Command>sort mylisturl by pv-* get # get pv-* desc get pv-* desc
Result> 0) Google.com
1) 19.60
2) Facebook.com
3) 11.62
4) Baidu.com
5) 8.87
6) Yahoo.com
7) 7.44
8) Youtube.com
9) 4.58


Join list with hash and string key with order

Example

Command>sort mylisturl by url-*->pv desc get # get pv-* get url-*->rank
Result> 0) Google.com
1) 19.60
2) 1
3) Facebook.com
4) 11.62
5) 2
6) Baidu.com
7) 8.87
8) 5
9) Yahoo.com
10) 7.44
11) 4
12) Youtube.com
13) 4.58
14) 3

View animation



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 hash SORT list SORT zset >>

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