Last active
August 2, 2025 03:27
-
-
Save patrickhulce/684cac2ac2589e349278 to your computer and use it in GitHub Desktop.
Find all keys without a TTL in Redis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Im pretty sure you can update this so it does it with a limit in batches 🤷♂️
Contributions welcome :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.