简体   繁体   English

Redis命令对键进行排序

[英]Redis Command To Sort Keys

The Redis command keys * will return a list of all keys and scan 0 is a more recent way to do something similar, but with less blocking. Redis 命令keys *将返回所有键的列表,而scan 0是一种最近的类似方法,但阻塞更少。 Do any commands exist that can sort the keys found, such as alphabetically, numerically, by creation timestamp, etc.?是否存在可以对找到的键进行排序的命令,例如按字母顺序、数字顺序、创建时间戳等?

Example of standard and fancy command sought:寻求标准和花式命令的示例:

standard keys post:* command:标准键 post:*命令:

post:2150
post:2400
post:1001
post:1006

fancy command to sort the keys alphabetically:按字母顺序对键进行排序的花哨命令

post:1001
post:1006
post:2150
post:2400

您始终可以使用完美运行的 unix 命令

redis-cli --scan --pattern yourpattern* | sort

Redis returns keys, using KEYS (don't use it in production!) or SCAN, unordered. Redis 使用 KEYS(不要在生产中使用它!)或 SCAN 无序返回密钥。 There is no "fancy" API to return them sorted but you can do it in the client application.没有“花哨的”API 来返回它们的排序,但您可以在客户端应用程序中进行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM