0

I think that there is something wrong with my Redis and web application deployment environment.

It would be grateful if someone could review my configurations and handle the case that I find tricky.


Redis configuration:

I have multiple Redis replicas configured, one as master and others as slaves. Let's say for simplification:

  • server1: configured as master
  • server2 ~ serverN: configured as slaves, referring to server1

Redis sentinel(s) may or may not be present in this structure, because I cannot guarantee that there will be at least servers.

In my situation, only server1 is guaranteed to exist, servers 2 to N are not.


Web application deployment environment:

I also have .NET web application(s) deployed using two connection strings, one for the master and another for one of the slaves. The web services use

The connection strings would look like this:

  • "server1,password=myredispassword" for Redis master
  • "serverN,password=myredispassword" for Redis slave

Of course, if a web application has a slave connection for serverN, then serverN is guaranteed to exist.


Problem Situation (and Question):

Now I think it would be possible to have a situation where there is a fallen Redis replica (master or slave), and my web application is referring to that fallen Redis replica via a connection string.

I presume that in such case the web application would go down, saying that the endpoint is unreachable.

Is it possible to gracefully handle the unreachable endpoint replica to another that is reachable? Do I need to configure Redis sentinels in order to do this? Or would you even say that my approach in trying to access or handle Redis connection is not correct? Thanks in advance for your opinion.

Shavakan
  • 61
  • 9
  • So the app with master connection string performs only write and other with slave's connection string only serves reads? – Atish Mar 14 '17 at 12:36
  • @Astro Umm, an app has both master and slave connections, but it writes using master's connection string and reads using slave's connection string. I thought this is the intended behavior of using replication? I'm wondering what will happen (and if I need to handle the case for) when slave goes down and the app attempts to read, or master goes down and the app attempts to write. – Shavakan Mar 15 '17 at 01:40
  • In both cases it should fail..since it has no idea that where to connect if one connection to one endpoint fails. This is usually handelled using sentinel – Atish Mar 15 '17 at 04:31

1 Answers1

1

This situation can be better handelled using redis sentinel. Your app connects to redis sentinel endpoint which:

  1. Provides automatic failover, when the master fails one of the slave node is automatically promoted to mater.

  2. Configuration provider: Sentinel acts as a configuration provider. With the sentinel connection string it determines the master and slave nodes. It also takes care forwarding your read request to slave and writes to master.

You application should connect to endpoint like below: IP: Port: i.e 26379

Make sure the driver attempts to connect newly elected master using sentinel endpoint whenever failover takes place.

Both redis and sentinel ports must be accessible from your application server.

Atish
  • 4,277
  • 2
  • 24
  • 32