1. 程式人生 > >輸出redis cluster叢集所有節點指定的引數的配置

輸出redis cluster叢集所有節點指定的引數的配置

需要:實現類似redis-trib.rb call 命令的功能,輸出redis cluster叢集所有節點指定的引數的配置

 

redis-trib.rb的輸出

[[email protected] ~]$ redis-trib.rb call 5.5.5.101:29001 config get *timeout*
/usr/local/ruby2.5.1/lib/ruby/gems/2.5.0/gems/redis-3.3.0/lib/redis/client.rb:459: warning: constant ::Fixnum is deprecated
>>> Calling CONFIG get
*timeout* 5.5.5.101:29001: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.101:29004: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.102:29001: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.101:29003: ["timeout", "0", "repl-timeout", "
60", "cluster-node-timeout", "15000"] 5.5.5.102:29004: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.103:29003: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.102:29002: ["timeout", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"] 5.5.5.103:29002: ["timeout
", "0", "repl-timeout", "60", "cluster-node-timeout", "15000"]

 

編寫指令碼

ip_port=`redis-cli -h $1 -p $2 -a abc123 -c cluster nodes | awk '{print $2}' | awk -F'@' '{print $1}'`

for i in $ip_port
do
    redis_ip=`echo $i | awk -F':' '{print $1}'|sed  's/\r//g'`
    redis_port=`echo $i | awk -F':' '{print $2}'|sed  's/\r//g'`
    redis_cmd="redis-cli -h $redis_ip -p $redis_port -a abc123 -c"
    echo -n "$redis_ip:$redis_port   "
    $redis_cmd  config get  $3 > config
    cat config | awk 'NR % 2 == 0' > even
    cat config | awk 'NR % 2 == 1' > odd
    paste -d ':' odd even > tmp.txt
    tail_line=$(cat tmp.txt|sed -n '$p')
    printf ''
    for x in `cat tmp.txt`
        do
            if [[ "$x" == "$tail_line" ]];then
               printf "%s" $x
            else
               printf '%s\t' $x
            fi        
        done
        printf ''
        echo
done

 

 

測試結果

[[email protected] ~]$ sh get_redis_para.sh 5.5.5.101 29001 *timeout*
5.5.5.101:29001   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.101:29004   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29001   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.101:29003   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29004   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.103:29003   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.102:29002   【timeout:0    repl-timeout:60    cluster-node-timeout:150005.5.5.103:29002   【timeout:0    repl-timeout:60    cluster-node-timeout:15000