0

We have a setup with :
2 php server
2 redis servers running as master/slave
1 Log server, which stores all kind of logs in elastcisearch

We want to implement automatic failover for redis servers, right now in php servers redis master address ir hardcoded.

And in log server, which has a logstash instance with redis input from master is also harcoded in logstash config.

We have installed redis sentinel on both redis servers and it's working fine.

But the problem is how to get master in php and logstash or that is not the right way.

For php I found this client wrapper https://github.com/Sparkcentral/PSRedis

But haven't found anything for logstash, I quess that I'm just searching in wrong direction

So the question is if this is the right direction if not someone could point me to it.

Kristapsv
  • 558
  • 5
  • 15

2 Answers2

5

In order to work with Sentinel remember you need three instances, so in your setup make sure to install a Sentinel instance in the log server, and one in each redis server instances as well. The three copies of Sentinel should run on computers / VMs that are believed to fail in a way independent to each other (so multiple VMs in the same physical host is not a good idea).

That said, in order to work for Sentinel your clients need to implement the Sentinel protocol as specified here: http://redis.io/topics/sentinel-clients.

In the https://github.com/Sparkcentral/PSRedis page I can't find any hint about what they exactly implement, are they implementing the latest Sentinel protocol as specified in my message above? I would open an issue and ask if they implement the documented Sentinel protocol: if no, they should, if yes, they should document them in the README.

Apparently Predis itself does not yet implement support for Sentinel: https://github.com/nrk/predis/issues/131

If you have some time to spend, I suggest to:

  1. Ask PSRedis what they exactly implement.
  2. Get familiar with the protocol described in the Sentinel doc, it's pretty basic stuff.
  3. Check yourself if PSRedis implements it in the correct way, if not, provide a pull request.

Happy hacking.

antirez
  • 18,314
  • 5
  • 50
  • 44
  • 1
    Now predis has supported redis-sentinel (https://github.com/nrk/predis): Support for master-slave replication setups and redis-sentinel. – MingalevME Mar 28 '17 at 09:32
-3

In Python if you want to know if your Redis is master do:

import redis

R = redis.Redis()
role = R.info()['role']
if role=='master':
   print 'I am master'
else:
   print 'I am slave'
Giovanni De Gasperis
  • 1,355
  • 1
  • 8
  • 3