Finding non-expiring keys in Redis

后端 未结 4 1794
盖世英雄少女心
盖世英雄少女心 2020-12-24 01:42

In my setup, the info command shows me the following:

[keys] => 1128
[expires] => 1125

I\'d like to find those 3 keys wi

4条回答
  •  爱一瞬间的悲伤
    2020-12-24 02:07

    @Waynn Lue's answer runs but uses the Redis KEYS command which Redis warns about:

    Warning: consider KEYS as a command that should only be used in production environments with extreme care. It may ruin performance when it is executed against large databases.

    Redis documentation recommends using SCAN.

    redis-cli --scan | while read LINE ; do TTL=`redis-cli ttl "$LINE"`; if [ $TTL -eq  -1 ]; then echo "$LINE"; fi; done;
    

    If you want to scan for a specific key pattern, use:

     redis-cli --scan --pattern "something*"
    

提交回复
热议问题