页面“多个git账号之间的切换 多个git账号指定不同的key”与“Redis批量删除key”之间的差异

来自linux中国网wiki
(页面间的差异)
跳到导航 跳到搜索
docker>Evan
(导入1个版本)
 
 
第1行: 第1行:
 +
[[category:ops]] [[category:redis]] 
  
多个git账号之间的切换 多个git账号指定不同的key
+
[[Redis-bigkeys]]
 +
=redis cluster 批量删除key=
 +
<pre>
 +
#June 19 2020  有空结果一下原来的版本再优化一下
 +
cat redis_del_key.sh
 +
#!/bin/bash
 +
# Usage
 +
#redis_list=("host:post" "host:post")
  
ssh可以通过-i使用指定的私钥文件,如:
+
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"
  
  ssh -i ~/mykey_rsa username@host
+
for info in ${redis_list[@]}
 +
    do
 +
        echo "开始执行:$info"  
 +
        ip=`echo $info | cut -d : -f 1`
 +
        port=`echo $info | cut -d : -f 2`
  
但是走ssh协议的git却没有类似的参数可以指定,只能是使用用户默认的ssh私钥。
+
      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
  
而git 一般也是用key认证的,如果你来我一样的情形 ,怎么办 ? 先假设我有两个账号,一个是github上的,一个是公司gitlab上面的。先为不同的账号生成不同的ssh-key
+
    done
 +
    echo "success done完成"
  
ssh-keygen  -t rsa -f ~/.ssh/id_rsa_work -C [email protected]
+
# cat key.txt
 +
infnce:wonderfulCache
 +
ext_info
  
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_work和id_rsa_work.pub两个文件,id_rsa_work.pub文件里存放的就是我们要使用的key
 
  
ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C [email protected]
 
  
然后根据提示连续回车即可在~/.ssh目录下得到id_rsa_github和id_rsa_github.pub两个文件,id_rsa_gthub.pub文件里存放的就是我们要使用的key
+
#原来的版本
  
编辑 ~/.ssh/config,设定不同的git 服务器对应不同的key
+
del hello_user_*
  
在本机添加
+
redis-cli keys
<pre>cat ~/.ssh/config
 
  
Host github.com
 
  hostname github.com
 
  User git
 
  #port 22
 
  IdentityFile /home/evan/.ssh/id_rsa_github
 
  IdentitiesOnly yes
 
 
 
</pre>
 
  
#建一个gitlab别名,新建的帐号使用这个别名做克隆和更新
+
redis-cli keys "hello_user_*" | xargs redis-cli del
<pre>Host 192.168.11.11
+
 
   HostName 192.168.11.11
+
 
   User work
+
./redis-cli -h IP -p PORT -a PASSWORD keys 'key*' | xargs  ./redis-cli -h IP  -p PORT -a PASSWORD del
   IdentityFile ~/.ssh/id_rsa_work
+
 
 +
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 {}
 +
 
 +
运行:
  
</pre>
+
./redis_del_key.sh  匹配的key*
  
打开 [https://github.com/settings/ssh https://github.com/settings/ssh] 把pub key (id_rsa_github.pub) 添加一下
+
err 
  
+
-i {} 都是一定要的
  
看到 You’ve successfully 就表示OK了
+
redis-cli -n 0 keys "test*" | xargs redis-cli -n 0 del
 +
(error) CROSSSLOT Keys in request don't hash to the same slot
  
多个git账号之间的切换 也可以多个github 帐号 [http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/ http://memoryboxes.github.io/blog/2014/12/07/duo-ge-gitzhang-hao-zhi-jian-de-qie-huan/]
+
</pre>
  
命令行下的git配置问题: 多个sshkey, 多个用户身份, git alias [http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/ http://www.liaohuqiu.net/cn/posts/git-setup-and-setting/]
+
=see also=
  
Git Config 命令查看配置文件 [https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/ https://cnbin.github.io/blog/2015/06/19/git-config-ming-ling-cha-kan-pei-zhi-wen-jian/]
 
  
ssh-keygen -t rsa -f ~/.ssh/id_rsa_evan -C [email protected]
+
[https://blog.csdn.net/yangyangye/article/details/100523387  redis集群批量删除模糊key shell脚本]
  
[https://www.linuxchina.net/?p=3393 https://www.linuxchina.net/?p=3393]
+
[https://www.cnblogs.com/feng0520/p/11067025.html  redis cluster集群批量删除中的key]
  
&nbsp;
+
[https://my.oschina.net/u/1255588/blog/1563672 Redis集群批量删除key]
  
&nbsp;
+
[https://blog.csdn.net/zj20142213/article/details/80879744  redis集群批量删除指定的key]
  
[[Category:git]]
+
https://blog.csdn.net/qq_36090419/article/details/80537684

2020年6月22日 (一) 11:37的版本


Redis-bigkeys

redis cluster 批量删除key

#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

see also

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

redis cluster集群批量删除中的key

Redis集群批量删除key

redis集群批量删除指定的key

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