Finding non-expiring keys in Redis

2019-02-01 04:21发布

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

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

I'd like to find those 3 keys without an expiration date. I've already checked the docs to no avail. Any ideas?

标签: redis
2条回答
太酷不给撩
2楼-- · 2019-02-01 04:26

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.

查看更多
Anthone
3楼-- · 2019-02-01 04:30

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.

查看更多
登录 后发表回答