你如何获得最后10个密钥redis?

Siv*_*iva 16 database web-applications key nosql redis

假设我有一个拥有1,000,000个密钥的数据库.有没有办法知道该数据库中的最后10个密钥?

gka*_*mal 5

您需要使用以下命令将其作为另一个列表进行维护。

Add new key to the front of the list  
LPUSH last10keys key

Retain only the last 10
LTRIM last10keys 0 9

Get the last keys - will return 10 or less
LRANGE mylist 0 9 
Run Code Online (Sandbox Code Playgroud)