Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis master/slave replication - single point of failure?

How does one upgrade to a newer version of Redis with zero downtime? Redis slaves are read-only, so it seems like you'd have to take down the master and your site would be read-only for 45 seconds or more while you waited for it to reload the DB.

Is there a way around this?

like image 756
nornagon Avatar asked Jan 18 '11 00:01

nornagon


People also ask

What happens when Redis master fails?

Sentinel is a system used to manage redis servers , it monitors the redis master and slaves continuously, and whenever a master goes down it will automatically promote a slave in to master. and when the old master is UP it will be made as slave of the new master.

Can Redis be replicated?

Redis uses asynchronous replication, with asynchronous replica-to-master acknowledges of the amount of data processed. A master can have multiple replicas. Replicas are able to accept connections from other replicas.

What is Redis failover?

Failover is the fault tolerance mechanism provided by Redis cluster, and one of the most core functions of the cluster. Failover supports two modes: Failure failover: Availability of an automatic recovery cluster. Artificial failover: Operable and maintainable operation of a support cluster.

Can Redis have multiple masters?

You can deploy as many masters as you want, with any number of slaves each, but they will behave like a single separated cluster with their own memory space, and it will be your responsibility at the application layer to spread your keys properly using each of the masters, just as you would do in a Memcached multi-node ...


2 Answers

Redis Team has very good documentation on this

Core Steps:

  • Setup your new Redis instance as a slave for your current Redis instance. In order to do so you need a different server, or a server that has enough RAM to keep two instances of Redis running at the same time.
  • If you use a single server, make sure that the slave is started in a different port than the master instance, otherwise the slave will not be able to start at all.
  • Wait for the replication initial synchronization to complete (check the slave log file).
  • Make sure using INFO that there are the same number of keys in the master and in the slave. Check with redis-cli that the slave is working as you wish and is replying to your commands.
  • Configure all your clients in order to use the new instance (that is, the slave).
  • Once you are sure that the master is no longer receiving any query (you can check this with the MONITOR command), elect the slave to master using the SLAVEOF NO ONE command, and shut down your master.

Full Documentation:

Upgrading or restarting a Redis instance without downtime

like image 190
kaji Avatar answered Sep 28 '22 11:09

kaji


When taking the node offline, promote the slave to master using the SLAVEOF command, then when you bring it back online you set it up as a slave and it will copy all data from the online node.

You may also need to make sure your client can handle changed/missing master nodes appropriately.

If you want to get really fancy, you can set up your client to promote a slave if it detects an error writing to the master.

like image 41
Tom Clarkson Avatar answered Sep 28 '22 11:09

Tom Clarkson