redis批量删除key

生成key

192.168.1.50:6379> set name1 hxl
OK
192.168.1.50:6379> set name2 hxl02
OK
192.168.1.50:6379> set name3 hxl03
OK
192.168.1.50:6379> get name1
"hxl"
192.168.1.50:6379> get name2
"hxl02"
192.168.1.50:6379> get name3
"hxl03"
192.168.1.50:6379> exit

批量删除
[root@cdc-henan-cdhworker02 /]# /usr/local/redis/bin/redis-cli -h 192.168.1.50 -p 6379 -a test123 KEYS "*name*"|xargs /usr/local/redis/bin/redis-cli -h 192.168.1.50 -a test123 del
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
(integer) 3

检查是否已经删除


[root@cdc-henan-cdhworker02 /]# /usr/local/redis/bin/redis-cli -h 192.168.1.50 -p 6379 -a test123
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.50:6379> get name1
(nil)
192.168.1.50:6379> get name2
(nil)
192.168.1.50:6379> get name3
(nil)
192.168.1.50:6379>

-- The End --

原文地址:https://www.cnblogs.com/hxlasky/p/14004685.html