7

I want to find any/all redis keys with TTL is -1. That's every key that is not set to expire. I've tried a couple GUI clients and none of them seem to off this functionality.

I found this answer which appears to offer a way to do it from the command line. But I get "invalid argument" errors when I try it locally or on my remote redis host.

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

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

What am I doing wrong? Is there a better way to do this?

Community
  • 1
  • 1
emersonthis
  • 32,822
  • 59
  • 210
  • 375

1 Answers1

0

The remote invocation will not work since you're pasting bash script into the prompt of redis-cli.

Also, try to use this on the conditional expressions: [[ $TTL -eq -1 ]]

(two brackets instead).

Niloct
  • 9,491
  • 3
  • 44
  • 57