How to delete keys for which the value matches a pattern in Redis?
$ redis-cli --scan --pattern "car:vw*" | xargs redis-cli del
redis-cli – the Redis command line interface. It has an interactive REPL (Read Eval Print Loop) mode where the user types Redis commands and received replies, and a command mode where
redis-cli is executed with additional arguments and the reply is printed to the standard output.
We use it in command mode to run the
--scan command with the
--pattern option that prints all the key names that match de specified pattern “car:vw*”.
xargs we use the output of the
--scan command as input for the
del command that removes the specified keys.