Skip to content

Instantly share code, notes, and snippets.

@patrickhulce
Last active July 10, 2023 10:09
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save patrickhulce/684cac2ac2589e349278 to your computer and use it in GitHub Desktop.
Save patrickhulce/684cac2ac2589e349278 to your computer and use it in GitHub Desktop.
Find all keys without a TTL in Redis
#!/bin/sh
redis-cli keys "*" | head -n $1 > keys.txt
cat keys.txt | xargs -n 1 -L 1 redis-cli ttl > ttl.txt
paste -d " " keys.txt ttl.txt | grep .*-1$ | cut -d " " -f 1 | redis-cli del
@murarisumit
Copy link

Just a note. It's very risky to run in production. Keys command is blocking command & if lot of keys redis will be blocked till command finishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment