SORT use hash

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

Using hash

Let's join the previous example using hash.
Enter rank and pv, which were stored as strings in the previous example, as hash.

Example

Command>hmset url-Google.com rank 1 pv 19.60
Result>OK
Command>hmset url-Facebook.com rank 2 pv 11.62
Result>OK
Command>hmset url-Youtube.com rank 3 pv 4.58
Result>OK
Command>hmset url-Yahoo.com rank 4 pv 7.44
Result>OK
Command>hmset url-Baidu.com rank 5 pv 8.87
Result>OK


Using hash

Let's join the previous example using hash.
To specify a hash field, use key->field.

Example

Command>sort myurl by url-*->rank get # get url-*->rank get url-*->pv    sort by rank  
Result> 0) Google.com
1) 1
2) 19.60
3) Facebook.com
4) 2
5) 11.62
6) Youtube.com
7) 3
8) 4.58
9) Yahoo.com
10) 4
11) 7.44
12) Baidu.com
13) 5
14) 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 SORT hash SORT list>>

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