Skip to content

Instantly share code, notes, and snippets.

@f9n
Forked from patrickhulce/findkeys.sh
Last active February 3, 2023 09:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save f9n/1240c5515079adf91b0427cfd60c5868 to your computer and use it in GitHub Desktop.
Save f9n/1240c5515079adf91b0427cfd60c5868 to your computer and use it in GitHub Desktop.
Delete all keys without a TTL in Redis
#!/bin/sh
LIMIT=$1
redis-cli keys "*" | head -n $LIMIT > 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 | xargs redis-cli del
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment