1

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?

j0k
  • 22,600
  • 28
  • 79
  • 90
Andy Fleming
  • 7,655
  • 6
  • 33
  • 53
  • You might want to read this: http://stackoverflow.com/questions/14941897/redis-cluster-production-ready – edwardmp Apr 19 '13 at 00:52
  • @edwardmp - The master/slave replication is different than "Redis Cluster", right? – Andy Fleming Apr 19 '13 at 00:54
  • Yep, usually a cluster is more like master/master. But I thought you might wanted to taak a look at the upcoming Redis Cluster. I think this can help you further, Redis Sentinel: http://redis.io/topics/sentinel – edwardmp Apr 19 '13 at 01:00
  • @edwardmp – Interesting. I'll check it out more. I'm hoping there is concise way to handle it on the PHP side. – Andy Fleming Apr 19 '13 at 01:06

1 Answers1

1

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.

Tommaso Barbugli
  • 11,781
  • 2
  • 42
  • 41