Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

redis: Handling failover?

Redis really seems like a great product with the built in replication and the amazing speed. After testing it out, it feels definitely like the 2010 replacement of memcached.

However, since when normally using memcached, a consistent hashing is being used to evenly spread out the data across the servers in a pool. If one of the servers in the pool goes down and stops being accessible, it is being handled transparently and only the keys that were lost will be recreated and evenly distributed across the remaining available servers in the pool.

Redis has on the other hand also built-in sharding, but also another really interesting feature called automatic replication. Thanks to that, availability of the data could be greatly increased while utilizing slave servers to use in the event of the shit hitting the fan.

However, I have yet not found any good solution to handle changing a redis server's status as a slave to become a new master automatically or by any other way automatically handling the failover with Redis.

How could this be done? What would be an appropriate approach to this?

like image 784
Industrial Avatar asked Jun 22 '10 21:06

Industrial


People also ask

How does Redis failover work?

How Redis offers High Availability and Automatic Failover ? Redis sentinel is the high availability solution offered by Redis. In case of a failure in your Redis cluster, Sentinel will automatically detects the point of failure and bring the cluster back to stable mode without any human intervention.

What causes a Redis failover?

An unplanned failover might happen because of hardware failure, network failure, or other unexpected outages to the primary node. The replica node promotes itself to primary, but the process takes longer. A replica node must first detect its primary node isn't available before it can start the failover process.

How long is Redis failover?

In Redis Cluster, when a primary node fails, the Redis cluster detects the failure and promotes a replica node to be the new primary for the shard. The cluster informs all nodes in the cluster and all clients about the change. This process should usually take about 30 seconds.

Should I use Redis Sentinel or cluster?

If you need an automatic failover solution without going to a complete cluster solution, use Sentinel. To get a complete cluster solution that splits your database between multiple nodes, then go for clustering.


1 Answers

However, since when normally using memcached, a consistent hashing is being used to evenly spread out the data across the servers in a pool. If one of the servers in the pool goes down and stops being accessible, it is being handled transparently and only the keys that were lost will be recreated and evenly distributed across the remaining available servers in the pool.

This is not what memcached does, the client library is doing all this magic ;)

However, I have yet not found any good solution to handle changing a redis server's status as a slave to become a new master automatically or by any other way automatically handling the failover with Redis.

Use the SlaveofCommand to change the characteristics. Automatic failover will need a bit more coding, connect to the server and if you loose the connection and can't establish it again for a time X then choose one slave to be master and change the slave-master-status of all other servers.

Update (01. Aug. 2012): There's now redis sentinel, a monitoring and automatic failover solution for version 2.4.16 and higher.

like image 106
Tobias P. Avatar answered Sep 28 '22 03:09

Tobias P.