zoukankan      html  css  js  c++  java
  • redis安全删key脚本(模糊匹配,长list,大set等)

    两种情况:

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

    2.删除一个大的list,set,zset,hash,这种得分批次减少大小,一直缩到0再删

    第一种情况:只要知道线上操作的时候我们要用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

    如果是大的list,set则需要用rem trim 等缩小尺寸再删

  • 相关阅读:
    Spring 事务管理
    016 sleep,wait,yield,join区别
    013 GC机制
    011 CountDownLatch,CyclicBarrier和Semaphore
    012 public等关键字可见性
    010 JVM类加载
    009 JVM内存结构以及GC机制
    008 BlockingQueue理解
    python3 正则表达式
    python django
  • 原文地址:https://www.cnblogs.com/wokofo/p/6893245.html
Copyright © 2011-2022 走看看