How would you get the last 10 keys redis? How would you get the last 10 keys redis? database database

How would you get the last 10 keys redis?


You will need to maintain it as another list using the following commands.

Add new key to the front of the list  LPUSH last10keys keyRetain only the last 10LTRIM last10keys 0 9Get the last keys - will return 10 or lessLRANGE mylist 0 9 


As a workaround if I don't want to change anything in the cache, I tail the AOF file to see what's the latest change there.

tail -f /var/lib/redis/appendonly.aof

From there, you can see the key, value and command used.


Some commands has [LIMIT offset count] wich you can fill and get limited number of items.

like zrevrangebyscore key +inf 0 LIMIT 0 20 which gives you top 20 items of a sorted set.