Redis批量删除脚本

Posted gjb724332682

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Redis批量删除脚本相关的知识,希望对你有一定的参考价值。

#! /bin/bash
 
# sh redis_del_batch.sh . localhost 7000 redis7000 *blacklist*
 
function redis_del(){
local host port key_pattern
 
echo "begin delete redis key , host :" $2 ", port :" $3 ", key pattern :" $5 "......"
 
host=$2
port=$3
passwd=$4
key_pattern=$5
total_sum=0
 
$1/redis-cli -h ${host} -p ${port} -a ${passwd} --scan --pattern ${key_pattern} | while read LINE
 
do
echo "delete key : " $LINE
$1/redis-cli -h ${host} -p ${port} -a ${passwd} del $LINE
total_sum=$(($total_sum+1))
echo "del key num : " $total_sum
done
 
echo "finish delete redis key , host :" $2 ", port :" $3 ", key pattern :" $5 "......"
}
 
redis_del $1 $2 $3 $4 $5

以上是关于Redis批量删除脚本的主要内容,如果未能解决你的问题,请参考以下文章

redis 批量删除key脚本

StackExchange.Redis加载Lua脚本进行模糊查询的批量删除和修改

redis cluster集群批量删除中的key

如何批量删除redis中keys

【redis】redis批量删除以指定内容开头的key

golang 根据keys获取的key列表批量删除