Redis教程

redis免交互式操作

本文主要是介绍redis免交互式操作,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一:免交互式初始化集群

echo "yes"|redis-cli --cluster create 10.0.0.101:6380 10.0.0.102:6380 10.0.0.103:6380 10.0.0.101:6381 10.0.0.102:6381 10.0.0.103:6381 --cluster-replicas 1

二:免交互式扩容

##删除目录下相关文件并重启
rm -rf /data/redis_6390/*

rm -rf /data/redis_6391/*

redis-server /opt/redis_6391/conf/redis_6391.conf
redis-server /opt/redis_6390/conf/redis_6390.conf

1添加主节点
redis-cli --cluster add-node 10.0.0.101:6390 10.0.0.101:6380

2添加从节点
redis-cli --cluster add-node 10.0.0.101:6391 10.0.0.101:6380 --cluster-slave --cluster-master-id $(redis-cli -c -h 10.0.0.101 -p 6380 cluster nodes|awk '/101:6390/{print $1}')

3重新分配槽
redis-cli --cluster reshard 10.0.0.101:6380 --cluster-from all --cluster-to $(redis-cli -c -h 10.0.0.101 -p 6380 cluster nodes|awk '/101:6390/{print $1}') --cluster-slots 4096 --cluster-yes

4查看

redis-cli --cluster info 10.0.0.101:6380

 

 

三:免交互式缩容

迁移槽
redis-cli --cluster rebalance 10.0.0.101:6380 --cluster-weight $(redis-cli -c -h 10.0.0.101 -p 6390 cluster nodes|awk '/101:6390/{print $1}')=0

##
--cluster-weight $(redis-cli -c -h 10.0.0.101 -p 6390 cluster nodes|awk '/101:6390/{print $1}')=0 #将下线节点ID设置为0

下线节点
redis-cli --cluster del-node 10.0.0.101:6391 $(redis-cli -c -h 10.0.0.101 -p 6380 cluster nodes|awk '/101:6391/{print $1}')
redis-cli --cluster del-node 10.0.0.101:6390 $(redis-cli -c -h 10.0.0.101 -p 6380 cluster nodes|awk '/101:6390/{print $1}')

这篇关于redis免交互式操作的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!