Finding non-expiring keys in Redis

In case somebody is getting bad arguments or wrong number of arguments error, put double quotes around $LINE.

So,it would be

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

This happens when there are spaces in the key.


Modified from a site that I can't find now.

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

edit: Note, this is a blocking call.


@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*"

Tags:

Redis