原理
使用redis-cli
工具配合xargs
命令
命令
- 查询
redis-cli [-h host] [-a password] [-p port] KEYS "{prefix}*" | wc -l
- 批量删除
redis-cli [-h host] [-a password] [-p port] KEYS "{prefix}*" | xargs -I key redis-cli [-h host] [-a password] [-p port] DEL "key"
- 批量打印并删除
redis-cli [-h host] [-a password] [-p port] KEYS "{prefix}*" | xargs -I key sh -c ' echo 准备删除["key"]; redis-cli [-h host] [-a password] [-p port] DEL "key" '