Home > Database > Redis > body text

How to sort list in redis

Release: 2019-07-04 15:07:48
Original
4957 people have browsed it

How to sort list in redis

Use sort to sort the list in redis.

The simplest way to use SORT is SORT key and SORT key DESC:

SORT key returns the result of sorting the key values ​​from small to large. SORT key DESC returns the results sorted from large to small by key value.

Example:

Assume that the today_cost list stores today's spending amount, then you can use the SORT command to sort it:

# 开销金额列表

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"
Copy after login

For more Redis related knowledge, please visitRedis usage tutorial column!

The above is the detailed content of How to sort list in redis. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!