redis安全删key脚本(模糊匹配,长list,大set等)
2017-05-23 11:26
621 查看
两种情况:
1.删除指定前缀开头的rediskey ,扫描和删除过程中对线上无感知
2.删除一个大的list,set,zset,hash,这种得分批次减少大小,一直缩到0再删
第一种情况:只要知道线上操作的时候我们要用scan来代替 keys ,这一点就行了,简单脚本如下:
del.sh
执行:
sh del.sh >>echo.log &
watch wc -l echo.log
如果是大的list,set则需要用rem trim 等缩小尺寸再删
1.删除指定前缀开头的rediskey ,扫描和删除过程中对线上无感知
2.删除一个大的list,set,zset,hash,这种得分批次减少大小,一直缩到0再删
第一种情况:只要知道线上操作的时候我们要用scan来代替 keys ,这一点就行了,简单脚本如下:
del.sh
#!/bin/bash for((i = 1; i <= 50000; i++)) do b=$[ $i * 100 ] echo $b 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 {} 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 {} 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 {} done
执行:
sh del.sh >>echo.log &
watch wc -l echo.log
如果是大的list,set则需要用rem trim 等缩小尺寸再删
相关文章推荐
- Redis客户端之Jedis(Key、String、Set、List、pub/sub、cluster、pool、pipleline)
- Redis用Java代码访问:Key、String、List、Set、Hash、SortSet
- Redis客户端之Jedis(Key、String、Set、List、pub/sub、cluster、pool、pipleline)
- Redis客户端之Jedis(Key、String、Set、List、pub/sub、cluster、pool、pipleline)
- redis之key、string、list、set、sort set、hash、精细持久化、snapshotting快照保存、主从模式
- redis安装及数据类型简介(string、list、set、sorted_set、hash)
- redis类型[string 、list 、 set 、sorted set 、hash]
- Redis应用场景 及其数据对象 string hash list set sortedset
- golang sortedset 实现(基于redis skiplist)
- Redis简介、与memcached比较、存储方式、应用场景、生产经验教训、安全设置、key的建议、安装和常用数据类型介绍、ServiceStack.Redis使用(1)
- redis数据类型List的安全队列和不安全队列
- redis类型[string 、list 、 set 、sorted set 、hash]
- Redis自学笔记 --Hash、List、Set类型简述
- redis 数据类型——key String Set
- redis生产环境中慎用keys模糊匹配方法
- Python下用List对员工信息表进行模糊匹配
- 错误:*** -[NSUserDefaults setObject:forKey:]: attempt to insert non-property list object
- hibernate -- 分页模糊查询中setParameter 和setParameterList
- redis的hash, list, set类型相关命令
- redis类型[string 、list 、 set 、sorted set 、hash]