Redis Wildcard Delete

Redis supports a keys command, which takes in a pattern, but you can’t use patterns for deletes. Fortunately awk and xargs makes this easy.

Just throw this on your server (somewhere in the PATH), chmod 755, and you’re good to go.

#!/bin/bash
redis-cli keys $1 | awk '{print $1}' | xargs --interactive redis-cli del {} \;

How to use:

redis-del pattern*
If you found this post helpful, please consider sharing to your network. I'm also available to help you be successful with your distributed systems! Please reach out if you're interested in working with me, and I'll be happy to schedule a free one-hour consultation.