首页 > 其他 > 详细

redis安全删key脚本

时间:2017-05-23 12:07:57      阅读:264      评论:0      收藏:0      [点我收藏+]

需求:

删除指定前缀开头的rediskey ,扫描和删除过程中对线上无感知

 

只要知道线上操作的时候我们要用scan来代替 keys ,这一点就行了,简单脚本如下:

 

del.sh

 1 #!/bin/bash
 2 
 3 for((i = 1; i <= 50000; i++))
 4 do
 5     b=$[ $i * 100 ]
 6     echo $b
 7         redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b  match cache:info_*  count 100 |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword  del {}
 8         redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b  match cache:userb*  count 100 |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword  del {}
 9         redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b  match cache:userc*  count 100 |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword  del {}
10 done

 

执行:

sh del.sh >>echo.log &

 

watch wc -l echo.log

 

 

这样就可以了,因为常用,记录一下。

 

redis安全删key脚本

原文:http://www.cnblogs.com/wokofo/p/6893245.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!