We have configured the Redis server with one master and two slaves. If my master fails, how can we handle the failover without restarting the Redis server.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Update:
Today, I would recommend checking out redis-sentinel, a tool by Redis’ author antirez for monitoring and automatic failover.
Original reply:
Check the
SLAVEOFcommand: http://redis.io/commands/slaveofWhen you discover that your master fails, issue a
SLAVEOF NO ONEon one of your slaves to promote it to master. Then point your other slave to it’s new master. See also “Upgrading or restarting a Redis instance without downtime”: http://redis.io/topics/adminFor managing configuration files you could do something along these lines (caution: Not tested, meant as an example). The example below assumes two configuration files for each server (
/etc/redis/server1.master.conf,/etc/redis/server1.slave.conf, etc), one having that server as a slave of some predefined master:Instead of having the predefined configuration files, you could edit them on the fly with e.g.
sed. Basically, you would make sure to always have aslaveofstanza in the configuration files, either pointing to a master orslaveof no one. Then rewrite the configuration usingsed(again, not tested, just meant as food for thought):