Search code examples
redisazure-redis-cache

Get list of all Redis keys and last access time


How can you get Redis to display all of it's current keys along side the last time they were accessed? Ideally in some kind of machine readable form but I'll take what I can get.


Solution

  • If you use the redis-cli command command on the portal, you can use the following method to get all the keys, and then get the last access time one by one.

    >SET title "The Hobbit"
    OK
    >GET title
    "The Hobbit"
    >KEYS *
    KEYS command is unsupported. Sending "SCAN 0 COUNT 1000 MATCH *" instead.
    1) "0"
    2) 1) "title"
    >object idletime title
    (integer) 126
    

    If you use code, it is much more convenient, and there are many ways to achieve it.

    You can refer below post.

    Delete redis keys that have been inactive for 30 days