Home  >  Article  >  Database  >  How to sort list in redis

How to sort list in redis

尚
Original
2019-07-04 15:07:484933browse

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"

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!

Statement:
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