Reputation: 7865
What is the best way to detect if a redis server is unavailable and failover to the slave?
Of course, this should be in a timely and efficient manner. I'm using it for centralized PHP session variable storage.
I saw this example on the nrk/predis repo but I believe it is only for sharding, not for failover/replication situations?
$redis = new Predis\Client(array(
array('host' => '10.0.0.1', 'port' => 6379),
array('host' => '10.0.0.2', 'port' => 6379)
));
TL;DR — I want my redis-based PHP sessions to failover to a slave redis server if the master is unavailable.
Help?
Upvotes: 1
Views: 3379
Reputation: 12031
Redis sentinel monitors the state of master redis machines and keeps track of connected slaves.
When a master goes down sentinel will promote one of the slaves as master.
Redis sentinel uses the same protocol as redis servers, clients can connect to redis sentinel to catch events like master down / master promoted etc etc.
It is up to you to notify clients about failovers.
Upvotes: 1