As describe here to upgrade a node we have to perform a set of operations over each node and depend on node type that operations are different. It would be great to include a two simple operations like up and down. Despite the name the idea is to make transparent the process of delete or add a node.
To get something similar to this feature I have used the redis-trib.rb commands in a shell script:
slave-ip() {
#slave0:ip=127.0.0.1,port=7003,state=online,offset=1695,lag=1
return $(redis-cli -p $PORT info | grep slave0 | cut -d: -f2 | cut -d= -f2 | cut -d, -f1)
}
failover() {
redis-cli -h $1 -p $PORT cluster failover
}
is-master() {
ROLE=$(redis-cli role 2> /dev/null | grep master | wc -l)
[ "${ROLE}" == "1" ] && return 0 || return 1
}
has-slave() {
NO_SLAVE_LINES=$(redis-cli -p $PORT info | grep connected_slaves:0 | wc -l)
[ "${NO_SLAVE_LINES}" == "1" ] && return 1 || return 0
}
rebalance (){
redis-trib rebalance $@ --use-empty-masters $NODE_IP
}
delete-node () {
if is-master ; then
if has-slave ; then
failover slave-ip
else
rebalance --weight $NODE_SHORT_ID=0.0
redis-trib del-node $OTHER_MASTER_IP $NODE_ID
rm $REDIS_CONF/$NODE_CONF_FILE
fi
fi
exit 0
}
add-node () {
if is-master ; then
redis-trib add-node $NODE_IP $OTHER_MASTER_IP
rebalance --weight $NODE_SHORT_ID=1.0
else
redis-trib add-node --slave $NODE_IP $OTHER_MASTER_IP
fi
exit 0
}
Comment From: thakurajayL
hi @jdvr , is this script part of codebase now ?
Thanks Ajay
Comment From: jdvr
No, this scripts is a helper for redis ansible role: https://github.com/idealista/redis-role
You can find it here