How to Remove Multiple Redis Cache

Tags: January 25, 2017 9:07 PM
1 comments

Goals

Remove multiple Redis cache key using one liner command.

Steps

Assume keys that we want to delete are keys beginning with 'laravel:' prefix.

$ redis-cli KEYS 'laravel:*'
1) "laravel:featured:2bf46b40ed15"
2) "laravel:list:5509f57fdaef"
3) "laravel:list:2bf46b40ed15"
4) "laravel:list:e1bf5bfc2ab8"
5) "laravel:list-total-rec:adc81409d693"
6) "laravel:list-total-rec:e1bf5bfc2ab8"
7) "laravel:promotion-list:adc81409d693"
8) "laravel:list:d1f68333e3bb"
9) "laravel:list:c6a45c5cf5c5"

Just pipe the output above to xargs command. By default redis-cli will use raw format when STDOUT is not tty, which in case is true for xargs.

$ redis-cli KEYS 'laravel:*' | xargs redis-cli DEL
(integer) 9

Reference

Share on Facebook Twitter