标签:cluster style abc gre 直接 printf for slot nbsp
需求:之前写的脚本(https://www.cnblogs.com/imdba/p/10197192.html),每个node上都只有一个slot段范围的情况,本次通过测试,实现了,任意段范围的获取方法。
key_slot=`redis-cli -h 5.5.5.101 -p 29001 -a abc123 -c cluster keyslot $1` node_slot=`sh get_slot_range2.sh 5.5.5.101 29001` find_tag=0 for i in $node_slot do node_ip=`echo $i | awk -F ‘[|]‘ ‘{print $1}‘` range_count=`echo $i | awk -F ‘[|]‘ ‘{print NF}‘` for (( rc=3;rc<=$range_count;rc++ )) do start_slot=`echo $i | awk -F ‘[|]‘ ‘{print $‘$rc‘}‘ | awk -F ‘[-]‘ ‘{print $1}‘` end_slot=`echo $i | awk -F ‘[|]‘ ‘{print $‘$rc‘}‘ | awk -F ‘[-]‘ ‘{print $2}‘` for(( j=$start_slot;j<=$end_slot;j++ )) do if [[ $j == $key_slot ]];then echo $node_ip find_tag=1 fi done if [[ $find_tag == 1 ]];then break fi done done 说明:get_slot_range2.sh,具体可以参考https://www.cnblogs.com/imdba/p/10115358.html redis-cli -h $1 -p $2 -c cluster nodes |grep master > ./all cat all | awk ‘{print $2}‘ | awk ‘$1 ~/@.*/{gsub("@.*","",$1);print $0}‘ > 222 cat all | awk -F " " ‘{for (i=9;i<=NF;i++)printf("%s", "|"$i);print ""}‘ > 999 paste -d "|" 222 999 > 2_9.txt cat 2_9.txt
key_slot=`redis-cli -h 5.5.5.101 -p 29001 -a abc123 -c cluster keyslot $1` node_slot=`sh get_slot_range2.sh 5.5.5.101 29001` find_tag=0 for i in $node_slot do node_ip=`echo $i | awk -F ‘[|]‘ ‘{print $1}‘` range_count=`echo $i | awk -F ‘[|]‘ ‘{print NF}‘` for (( rc=3;rc<=$range_count;rc++ )) do start_slot=`echo $i | awk -F ‘[|]‘ ‘{print $‘$rc‘}‘ | awk -F ‘[-]‘ ‘{print $1}‘` end_slot=`echo $i | awk -F ‘[|]‘ ‘{print $‘$rc‘}‘ | awk -F ‘[-]‘ ‘{print $2}‘` [ $key_slot -gt $start_slot -a $key_slot -le $end_slot ] && echo $node_ip done done
#感谢浩神,上面标红的可以直接用一个判断获取,不需要循环。
标签:cluster style abc gre 直接 printf for slot nbsp
原文地址:https://www.cnblogs.com/imdba/p/10209655.html