两种情况:
1.删除指定前缀开头的rediskey ,扫描和删除过程中对线上无感知
2.删除一个大的list,set,zset,hash,这种得分批次减少大小,一直缩到0再删
第一种情况:只要知道线上操作的时候我们要用scan来代替 keys ,这一点就行了,简单脚本如下:
del.sh
#!/bin/bash for((i = ; i <= ; i++))
do
b=$[ $i * ]
echo $b
redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b match cache:info_* count |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword del {}
redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b match cache:userb* count |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword del {}
redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword scan $b match cache:userc* count |xargs -i redis-cli -h test.m.cnhza.kvstore.aliyuncs.com -a test:Paasword del {}
done
执行:
sh del.sh >>echo.log &
watch wc -l echo.log
如果是大的list,set则需要用rem trim 等缩小尺寸再删