Skip to content

Instantly share code, notes, and snippets.

@lucassabreu
Last active May 22, 2020 19:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucassabreu/63217236273a8308dd365044343c8669 to your computer and use it in GitHub Desktop.
Save lucassabreu/63217236273a8308dd365044343c8669 to your computer and use it in GitHub Desktop.
A redis-cli helper to delete keys by a pattern (using docker run)
#!/bin/bash
if [ "$1" -eq '--help' ] && {
echo "usage: redis-cli-del-keys.sh <pattern e.g. user:*> -h <hostname> -n <db-number> [<other connection parameters|...>]"
exit 1
}
docker run --rm redis redis-cli ${@:2} --scan --pattern $1 | sort | uniq | sed 's|\s\+| |g' | xargs docker run --rm redis redis-cli ${@:2} del
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment