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!