title: How to find redis keys by TTL
body: <p>I want to find any/all redis keys with TTL is <code>-1</code>. 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.</p>
  
  <p>I found <a href="https://stackoverflow.com/questions/9817951/finding-non-expiring-keys-in-redis">this answer</a> 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.</p>
  
  <p>LOCAL
  <code>
  redis-cli keys  "*" | while read LINE ; do TTL=`redis-cli ttl $LINE`; if [ $TTL -eq  -1 ]; then echo "$LINE"; fi; done;
  </code></p>
  
  <p>REMOTE
  <code>
  $redis-cli -h ... -p ... -a
  redis&gt;&gt; keys  "*" | while read LINE ; do TTL=`redis-cli ttl $LINE`; if [ $TTL -eq  -1 ]; then echo "$LINE"; fi; done;
  </code></p>
  
  <p>What am I doing wrong? Is there a better way to do this?</p>