“Redis批量删除key”的版本间的差异

来自linux中国网wiki
跳到导航 跳到搜索
 
(未显示同一用户的17个中间版本)
第2行: 第2行:
  
 
[[Redis-bigkeys]]
 
[[Redis-bigkeys]]
 +
 +
ulink
 +
[https://cloud.tencent.com/developer/article/1530197 Redis 高效删除大key]
 
=redis cluster 批量删除key=
 
=redis cluster 批量删除key=
 +
 +
== 正则匹配删除 之hello项目的版本==
 +
 +
<pre>
 +
 +
redisloop-re.sh
 +
#!/bin/bash
 +
#Usage  模糊删除 key  key name 写在  rr 文件里 如  hello_user_*  #这个用法是  bash redisloop-re.sh
 +
#for line  in  `cat $1`  #这个用法是  bash redisloop-re.sh  rr
 +
for line  in  `cat rr`
 +
#cat  $1
 +
#cat  $1  | while read line
 +
do
 +
#echo $line
 +
 +
redis-cli  -c  -h 172.31.22.218 -p 7000  -a hellopass keys $line |xargs  -r -t -n1 redis-cli  -c  -h  172.31.22.218  -p 7000  -a hellopas  del
 +
redis-cli  -c  -h 172.31.22.218 -p 7001  -a hellopass keys $line | xargs  -r -t -n1 redis-cli  -c  -h 172.31.22.218  -p 7001  -a hellopass  del 
 +
redis-cli  -c  -h 172.31.16.135 -p 7002  -a hellopas keys $line | xargs  -r -t -n1  redis-cli  -c  -h  172.31.16.135  -p 7002  -a hellopass del
 +
redis-cli  -c  -h 172.31.16.135 -p 7003 -a hellopass keys  $line | xargs -r -t -n1  redis-cli -c  -h  172.31.16.135  -p 7003  -a hellopassw del
 +
redis-cli  -c  -h 172.31.23.43 -p 7004 -a hellopassw  keys  $line | xargs  -r -t -n1 redis-cli  -c  -h  172.31.23.43  -p 7004  -a hellopass  del
 +
redis-cli  -c  -h 172.31.23.43 -p 7005  -a hellopassw keys  $line | xargs  -r -t -n1 redis-cli  -c  -h  172.31.23.43  -p 7005  -a hellopas  del
 +
done
 +
 +
 +
 +
 +
done
 +
 +
</pre>
 +
 +
 +
==在集群中删除多个指定的key ==
 +
 +
<pre>
 +
删除单个的 如下
 +
cat redisloop.sh
 +
#!/bin/bash
 +
#模糊删除 key  在re.sh 那个脚本里面
 +
# Usage  bash  redisloop.sh  你的文件  # 文件内容样子  del token_resp11916485
 +
cat  $1  | while read line
 +
do
 +
 +
redis-cli    -c  -h    172.31.22.218  -p 7000  -a hellopass $line
 +
redis-cli    -c  -h    172.31.22.218  -p 7001  -a hellopass  $line
 +
redis-cli    -c  -h  172.31.16.135  -p 7002  -a hellopassw  $line 
 +
redis-cli    -c  -h  172.31.16.135  -p 7003  -a hellopassw  $line
 +
redis-cli    -c  -h  172.31.23.43  -p 7004  -a hellopassw  $line
 +
redis-cli    -c  -h  172.31.23.43  -p 7005  -a hellopassw  $line
 +
</pre>
 +
 +
 +
 
<pre>
 
<pre>
 +
#pre
 +
 +
删除单个:del key
 +
 +
删除多个:redis-cli -a pass(密码) keys "WX_ACT_USER_KEY_*" | xargs redis-cli -a pass(密码) del
 +
 +
 +
 
#June 19 2020  有空结果一下原来的版本再优化一下  
 
#June 19 2020  有空结果一下原来的版本再优化一下  
 
cat redis_del_key.sh
 
cat redis_del_key.sh
第78行: 第141行:
  
 
</pre>
 
</pre>
 +
 +
=del相关=
 +
 +
命令和DEL十分相似:删除指定的key(s),若key不存在则该key被跳过。但是,相比DEL会产生阻塞,该命令会在另一个线程中回收内存,因此它是非阻塞的。 这也是该命令名字的由来:仅将keys从keyspace元数据中删除,真正的删除会在后续异步操作。
 +
http://www.redis.cn/commands/unlink.html
 +
 +
 +
[https://www.zybuluo.com/phper/note/609318 redis 中pipline,mset, mget使用对比]
 +
 +
[https://blog.csdn.net/wojiuguowei/article/details/85096609  redis del与unlink命令用法及实现]
 +
 +
[https://yq.aliyun.com/articles/743207  Redis:del/unlink 命令源码解析]
 +
 +
[https://www.cnblogs.com/0201zcr/p/9647787.html  redis批量删除key 远程批量删除key ]
 +
 +
 +
[https://www.cnblogs.com/kiko2014551511/p/11531584.html Redis批量删除key的命令]
 +
 +
[https://www.php.cn/redis/447726.html redis中批量删除key的方法]
  
 
=see also=
 
=see also=
 +
[https://blog.csdn.net/xujiamin0022016/article/details/103020025?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.nonecase  如何优雅地删除Redis大键]
  
 +
[https://blog.csdn.net/yangyangye/article/details/100523387  redis集群批量删除模糊key shell脚本]
  
 
[https://blog.csdn.net/yangyangye/article/details/100523387  redis集群批量删除模糊key shell脚本]
 
[https://blog.csdn.net/yangyangye/article/details/100523387  redis集群批量删除模糊key shell脚本]
第87行: 第171行:
  
 
[https://my.oschina.net/u/1255588/blog/1563672 Redis集群批量删除key]
 
[https://my.oschina.net/u/1255588/blog/1563672 Redis集群批量删除key]
 +
 +
[https://www.cnblogs.com/0201zcr/p/9647787.html  redis批量删除key 远程批量删除key ]
  
 
[https://blog.csdn.net/zj20142213/article/details/80879744  redis集群批量删除指定的key]
 
[https://blog.csdn.net/zj20142213/article/details/80879744  redis集群批量删除指定的key]
  
 
https://blog.csdn.net/qq_36090419/article/details/80537684
 
https://blog.csdn.net/qq_36090419/article/details/80537684
 +
 +
[https://www.cnblogs.com/DreamDrive/p/5772198.html  Redis中的批量删除数据库中的Key]
 +
 +
[https://www.cnblogs.com/DreamDrive/p/5772198.html Redis中的批量删除数据库中的Key]

2020年9月14日 (一) 03:41的最新版本


Redis-bigkeys

ulink Redis 高效删除大key

redis cluster 批量删除key

正则匹配删除 之hello项目的版本


redisloop-re.sh 
#!/bin/bash
#Usage  模糊删除 key  key name 写在  rr 文件里 如  hello_user_*  #这个用法是   bash redisloop-re.sh
#for line  in  `cat $1`  #这个用法是   bash redisloop-re.sh   rr 
for line  in  `cat rr`
#cat  $1 
#cat  $1  | while read line
do
#echo $line

redis-cli  -c  -h 172.31.22.218 -p 7000  -a hellopass keys $line |xargs  -r -t -n1 redis-cli  -c  -h  172.31.22.218   -p 7000  -a hellopas  del
redis-cli  -c  -h 172.31.22.218 -p 7001  -a hellopass keys $line | xargs   -r -t -n1 redis-cli  -c  -h 172.31.22.218   -p 7001  -a hellopass  del   
redis-cli  -c  -h 172.31.16.135 -p 7002  -a hellopas keys $line | xargs  -r -t -n1  redis-cli  -c  -h   172.31.16.135   -p 7002  -a hellopass del
redis-cli  -c  -h 172.31.16.135 -p 7003 -a hellopass keys  $line | xargs -r -t -n1  redis-cli -c  -h   172.31.16.135   -p 7003  -a hellopassw del 
redis-cli  -c  -h 172.31.23.43 -p 7004 -a hellopassw  keys  $line | xargs   -r -t -n1 redis-cli  -c  -h   172.31.23.43   -p 7004  -a hellopass   del
redis-cli  -c  -h 172.31.23.43 -p 7005  -a hellopassw keys  $line | xargs   -r -t -n1 redis-cli   -c  -h   172.31.23.43   -p 7005  -a hellopas  del 
done




done


在集群中删除多个指定的key

删除单个的 如下 
 cat redisloop.sh
#!/bin/bash
#模糊删除 key   在re.sh 那个脚本里面
# Usage   bash  redisloop.sh  你的文件  # 文件内容样子   del token_resp11916485
cat  $1  | while read line
do

redis-cli    -c  -h    172.31.22.218   -p 7000  -a hellopass $line
redis-cli    -c  -h    172.31.22.218   -p 7001  -a hellopass  $line
redis-cli    -c  -h   172.31.16.135   -p 7002  -a hellopassw   $line  
redis-cli    -c  -h   172.31.16.135   -p 7003  -a hellopassw  $line
redis-cli    -c  -h   172.31.23.43   -p 7004  -a hellopassw  $line
redis-cli    -c  -h   172.31.23.43   -p 7005  -a hellopassw   $line


#pre

删除单个:del key

删除多个:redis-cli -a pass(密码) keys "WX_ACT_USER_KEY_*" | xargs redis-cli -a pass(密码) del



#June 19 2020   有空结果一下原来的版本再优化一下 
cat redis_del_key.sh
#!/bin/bash
# Usage 
#redis_list=("host:post" "host:post")

redis_list=( "172.16.200.12:7003" "172.16.200.7:7004" "172.16.200.7:7005" "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=( "172.16.200.13:7000" "172.16.200.13:7001" "172.16.200.12:7002")
#redis_list=("172.16.200.7:7004")
password="3636password"

for info in ${redis_list[@]}
    do
        echo "开始执行:$info"  
        ip=`echo $info | cut -d : -f 1`
        port=`echo $info | cut -d : -f 2`

      for  loop in  `cat key.txt`
         do
         #echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c del
         echo $loop  |xargs -t -n1 redis-cli -c  -h $ip -p $port -a $password -c keys 
         done

    done
    echo "success done完成"

# cat key.txt 
infnce:wonderfulCache
ext_info



#原来的版本

del hello_user_* 

redis-cli keys


 redis-cli keys "hello_user_*" | xargs redis-cli del


./redis-cli -h IP -p PORT -a PASSWORD keys 'key*' | xargs  ./redis-cli -h IP  -p PORT -a PASSWORD del

redis-cli    -c  -h    172.31.22.218   -p 7000  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218   -p 7000  -a pass  del {}
redis-cli    -c  -h    172.31.22.218   -p 7001  -a pass keys 'hello_user_*'| xargs -i redis-cli    -c  -h    172.31.22.218   -p 7001  -a pass  del {}

redis-cli    -c  -h    172.31.16.135  -p 7002  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.16.135   -p 7002 -a pass  del {}
redis-cli    -c  -h    172.31.16.135  -p 7003  -a pass keys 'hello_user_*'| xargs  -i redis-cli    -c  -h    172.31.16.135   -p 7003 -a pass  del {}

redis-cli    -c  -h     172.31.23.43   -p 7004  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43   -p 7004 -a pass  del {}
redis-cli    -c  -h     172.31.23.43   -p 7005  -a pass keys 'hello_user_*'| xargs -i  redis-cli    -c  -h    172.31.23.43   -p 7005 -a pass  del {}



#!/bin/bash
redis_comm=/usr/local/redis-5.0.3/bin/redis-cli
redis_ser01=192.168.50.175
redis_ser02=192.168.50.174
$redis_comm -c -h $redis_ser01  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser01  -p 7001 -a xxx del {}
$redis_comm -c -h $redis_ser02  -p 7001 -a xxx  keys $1 | xargs -i $redis_comm -c -h $redis_ser02  -p 7001 -a xxx del {}

运行:

./redis_del_key.sh  匹配的key*

err  

-i  {} 都是一定要的 

redis-cli -n 0 keys "test*" | xargs redis-cli -n 0 del
(error) CROSSSLOT Keys in request don't hash to the same slot

del相关

命令和DEL十分相似:删除指定的key(s),若key不存在则该key被跳过。但是,相比DEL会产生阻塞,该命令会在另一个线程中回收内存,因此它是非阻塞的。 这也是该命令名字的由来:仅将keys从keyspace元数据中删除,真正的删除会在后续异步操作。 http://www.redis.cn/commands/unlink.html


redis 中pipline,mset, mget使用对比

redis del与unlink命令用法及实现

Redis:del/unlink 命令源码解析

redis批量删除key 远程批量删除key


Redis批量删除key的命令

redis中批量删除key的方法

see also

如何优雅地删除Redis大键

redis集群批量删除模糊key shell脚本

redis集群批量删除模糊key shell脚本

redis cluster集群批量删除中的key

Redis集群批量删除key

redis批量删除key 远程批量删除key

redis集群批量删除指定的key

https://blog.csdn.net/qq_36090419/article/details/80537684

Redis中的批量删除数据库中的Key

Redis中的批量删除数据库中的Key