Skip to content

Instantly share code, notes, and snippets.

@Gowiem
Last active February 15, 2016 20:27
Show Gist options
  • Save Gowiem/d4916fca2503951350fc to your computer and use it in GitHub Desktop.
Save Gowiem/d4916fca2503951350fc to your computer and use it in GitHub Desktop.
Clean up Redis by deleting keys
# Pull all keys matching wildcard from your Replica so you're not using KEYS on your primary.
$ redis-cli -h $ELASTI_CACHE_REPLICA_URL KEYS "*WILDCARD*" > keys.txt
# For each key that has been collected, prepend the DEL command.
$ sed ':a;N;$!ba;s/\n/\n DEL /g' keys.txt > del_keys.txt
# Feed the new DEL commands into your primary. Run via nohup + background as deleting millions of keys can take hours.
$ nohup redis-cli -h $ELASTI_CACHE_URL < del_keys.txt &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment