3.4 排序相关命令
Last updated
127.0.0.1:6379> SORT salary ASC
1) "10000"
2) "12000"
3) "13500"
4) "15000"127.0.0.1:6379> LRANGE salary 0 -1
1) "12000"
2) "13500"
3) "15000"
4) "10000"127.0.0.1:6379> SADD name 'Peter' 'Tom' 'Mary'
(integer) 3127.0.0.1:6379> SORT name DESC
(error) ERR One or more scores can't be converted into double127.0.0.1:6379> SORT name DESC ALPHA
1) "Tom"
2) "Peter"
3) "Mary"127.0.0.1:6379> ZADD nameSet 4.0 Mike 2.0 Peter 1.0 Tim 0.5 Johnson
(integer) 4127.0.0.1:6379> SORT nameSet ASC ALPHA
1) "Johnson"
2) "Mike"
3) "Peter"
4) "Tim"127.0.0.1:6379> SORT nameSet DESC ALPHA
1) "Tim"
2) "Peter"
3) "Mike"
4) "Johnson"127.0.0.1:6379> LPUSH vipLevel VIP1 VIP3 VIP2
(integer) 3127.0.0.1:6379> SORT vipLevel DESC BY VIP*
1) "VIP3"
2) "VIP2"
3) "VIP1"127.0.0.1:6379> RPUSH number 1 3 2 4 6 5 8 7
(integer) 8127.0.0.1:6379> SORT number LIMIT 0 3 ASC
1) "1"
2) "2"
3) "3"127.0.0.1:6379> SORT number LIMIT 4 2 ASC
1) "5"
2) "6"127.0.0.1:6379> LPUSH score 100 80 90 85
(integer) 4127.0.0.1:6379> SET name-100 Peter-100
OK
127.0.0.1:6379> SET name-80 Mary-80
OK127.0.0.1:6379> SET symbol-90 RMB-90
OK
127.0.0.1:6379> SET symbol-85 USD-85
OK127.0.0.1:6379> SORT score GET name-* ASC
1) "Mary-80"
2) (nil)
3) (nil)
4) "Peter-100"127.0.0.1:6379> SORT score GET symbol-* DESC
1) (nil)
2) "RMB-90"
3) "USD-85"
4) (nil)127.0.0.1:6379> SORT score GET name-* GET symbol-* DESC
1) "Peter-100" // name-100
2) (nil) // symbol-100
3) (nil) // name-90
4) "RMB-90" // symbol-90
5) (nil) // name-85
6) "USD-85" // symbol-85
7) "Mary-80" // name-80
8) (nil) // symbol-80127.0.0.1:6379> LRANGE score 0 -1
1) "85"
2) "90"
3) "80"
4) "100"127.0.0.1:6379> SORT score DESC STORE score-desc
(integer) 4127.0.0.1:6379> LRANGE score-desc 0 -1
1) "100"
2) "90"
3) "85"
4) "80"