redis批量删除key

Posted 东南风

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 --


























以上是关于redis批量删除key的主要内容,如果未能解决你的问题,请参考以下文章

golang 根据keys获取的key列表批量删除

对于redis的批量删除指定key,有没有好的方法

Redis 批量删除key

Redis:按照正则批量删除key

Redis批量删除keys

Redis 批量删除Redis的key 正则匹配删除