Skip to content

Commit

Permalink
added function to reconnect to master.
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadQadora committed Nov 25, 2024
1 parent 2e602eb commit e703bfe
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions falkordb-cluster/cluster-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ if [[ $RUN_METRICS -eq 1 ]]; then
redis_exporter_pid=$!
fi

reconnect_to_master(){
res=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING info replication)
if [[ -n $res ]];then
master_info=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING info replication | grep role)
if [[ $master_info == *"role:slave"* ]];then
ip="$(echo "$res" | grep master_host | cut -d':' -f2 | tr -d '[:space:]')"
master_node_id=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING cluster nodes | grep $"ip")
echo "The master node id is: $master_node_id"
redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING cluster replicate $master_node_id
else
echo "Node is a master, no need to resolve master hostname."
fi
else
echo "Replication did not happen yet,first time running the redis server."
fi

}

reconnect_to_master

while true; do
sleep 1
done

0 comments on commit e703bfe

Please sign in to comment.