获取指定key对应的node节点信息
2024-09-04 21:25:24
需求:之前写的脚本(https://www.cnblogs.com/imdba/p/10197192.html),每个node上都只有一个slot段范围的情况,本次通过测试,实现了,任意段范围的获取方法。
key_slot=`redis-cli -h 5.5.5.101 -p -a abc123 -c cluster keyslot $` node_slot=`sh get_slot_range2.sh 5.5.5.101 ` find_tag=
for i in $node_slot
do
node_ip=`echo $i | awk -F '[|]' '{print $1}'`
range_count=`echo $i | awk -F '[|]' '{print NF}'`
for (( rc=;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 $ -p $ -c cluster nodes |grep master > ./all
cat all | awk '{print $2}' | awk '$1 ~/@.*/{gsub("@.*","",$1);print $0}' >
cat all | awk -F " " '{for (i=9;i<=NF;i++)printf("%s", "|"$i);print ""}' >
paste -d "|" > 2_9.txt
cat 2_9.txt
key_slot=`redis-cli -h 5.5.5.101 -p -a abc123 -c cluster keyslot $` node_slot=`sh get_slot_range2.sh 5.5.5.101 ` find_tag=
for i in $node_slot
do
node_ip=`echo $i | awk -F '[|]' '{print $1}'`
range_count=`echo $i | awk -F '[|]' '{print NF}'`
for (( rc=;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 #感谢浩神,上面标红的可以直接用一个判断获取,不需要循环。
最新文章
- XPatchLib 对象增量数据序列化及反序列化器 For .Net
- JavaScript基础整理(2)
- Union-Find Algorithm
- Java - Collection 高效的找出两个List中的不同元素
- atitit.hbnt orm db 新新增更新最佳实践o99
- 简单的freemarker解析测试
- poj1182(食物链)续
- STM32中的位带(bit-band)操作
- codevs1099字串变换(Bfs)
- linux经常使用解压缩命令
- 自然饱和度(Vibrance)算法的模拟实现及其SSE优化(附源码,可作为SSE图像入门,Vibrance算法也可用于简单的肤色调整)。
- deviceMotion.userAcceleration加速度方向
- Tars 负载均衡
- SpringSecurity如何在代码中获取认证用户信息
- :app:compileDebugJavaWithJavac
- shell 文件描述符
- 20155207 EXP7 网络欺诈技术防范
- js中parentNode,parentElement,childNodes,children
- Python MySQLdb模块连接操作mysql数据库实例_python
- c#实现图片二值化例子(黑白效果)