Linux 拨号vps windows公众号手机端

redis中怎么对list排序

lewis 7年前 (2018-09-29) 阅读数 12 #VPS/云服务器
文章标签 listredis

redis中对list排序的示例:

在redis中使用sort对list进行排序。

sort使用方法:

sort key //返回键值从小到大排序的结果

sort key desc //返回键值从大到小排序的结果

例子:

假设today_cost列表保存了今日的开销金额,使用sort对today_cost进行排序,代码如下:

# 开销金额列表

redis> LPUSH today_cost 30 1.5 10 8

(integer) 4

# 排序

redis> SORT today_cost

1) "1.5"

2) "8"

3) "10"

4) "30"

# 逆序排序

redis 127.0.0.1:6379> SORT today_cost DESC

1) "30"

2) "10"

3) "8"

4) "1.5"

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门