1. 程式人生 > >【Redis】RedisCluster 批量刪除key

【Redis】RedisCluster 批量刪除key

  1. 首先使用客戶端redis-cli連線你的RedisCluster其中任何一個節點

    redis-cli -h host -p post -a password
  2. 檢視叢集資訊,找出所有的master節點, 命令如下

    cluster nodes
  3. 修改如下shell指令碼(redis_delete_key.sh),redis_list為叢集主節點,password是你的叢集密碼

    redis_list=("host:post" "host:post")
    password="redispassword=="
    
    for info in ${redis_list[@]}
        do
            echo
    "開始執行:$info" ip=`echo $info | cut -d : -f 1` port=`echo $info | cut -d : -f 2` cat key.txt |xargs -t -n1 redis-cli -h $ip -p $port -a $password -c del done echo "完成"
  4. 找出所有要刪除的key,輸出到文字key.txt裡(這裡找的是所有baidu_字首的key)

    redis-cli -h 10.16.1.1 -p 6389 keys "baidu_*" >>
    key.txt
  5. 執行指令碼,開始批量刪除,當key比較多的時候,耗時較長

    sh redis_delete_key.sh