Redis 排序

sort 排序命令, 通过alpha实现对字典顺序排序, desc 实现元素按从大到小的顺序排列

# 对集合排序
127.0.0.1:6379> sadd tag:ruby:post 2 6 12 26
(integer) 4
127.0.0.1:6379> sort tag:ruby:post
1) "2"
2) "6"
3) "12"
4) "26"

# 对列表排序
127.0.0.1:6379> lpush mylist 4 2 6 1 3 7
(integer) 6
127.0.0.1:6379> sort mylist
1) "1"
2) "2"
3) "3"
4) "4"
5) "6"
6) "7"

# 对有序集合排序
127.0.0.1:6379> zadd myzset 50 2 40 3 20 1 60 5
(integer) 4
127.0.0.1:6379> sort myzset
1) "1"
2) "2"
3) "3"
4) "5"

# 对字典顺序排序排列非数字元素
127.0.0.1:6379> lpush mylistalpha a c e d B C A
(integer) 7
127.0.0.1:6379> sort mylistalpha
(error) ERR One or more scores can't be converted into double
127.0.0.1:6379> sort mylistalpha alpha
1) "a"
2) "A"
3) "B"
4) "c"
5) "C"
6) "d"
7) "e"

# desc实现从大到小的顺序排序
127.0.0.1:6379> sort tag:ruby:post desc
1) "26"
2) "12"
3) "6"
4) "2"
posted @ 2020-08-14 14:17  phper-liunian  阅读(134)  评论(0编辑  收藏  举报