Redis Sentinel

Redis replication is a very simple to use and configure master-slave replication that allows slave Redis servers to be exact copies of master servers. The following are some very important facts about Redis replication:

      • Redis uses asynchronous replication. Starting with Redis 2.8, however, slaves will periodically acknowledge the amount of data processed from the replication stream.
      • A master can have multiple slaves.
      • Slaves are able to accept connections from other slaves. Aside from connecting a number of slaves to the same master, slaves can also be connected to other slaves in a graph like structure.
      • Redis replication is nonblocking on the master side. This means that the master will continue to handle queries when one or more slaves perform the initial synchronization.
Redis Sentinel (Master-Slave)

Redis Sentinel (Active-Passive) is only one Redis instance, the master, serving requests at all time. Data is replicated from the master to the rest of the Redis instances, the slaves. One of the slaves would replace the master when the master is down. Therefore HA essentially needs to take care of two major issues, data availability and service availability. Redis replication provides data availability, service availability and monitors Redis instances. For example, consider a group of three Redis instances, A, B, and C, with A as the initial master. The following figure illustrate how Redis Sentinel monitors Redis instances.

Redis Sentinal (Master-Slave) failover

When the master is down, Redis Sentinel automatically elects a new master and failover to the the new master as shown in the following figure.

Redis Sentinal (Master-Slave) failover

Sentinel Configuration Changes:

The master data-sets are immediately replicated into slave and the master fails the slave turn into master, slave fails master take care the process. In this, we need to change the configurations in both master and slave. The changes are below,

Redis master changes:

redis.conf

      • port <port number> // for redis server port
        • ex: port 6379
      • slave-read-only no

sentinel.conf

      • port <port number> // for redis sentinel port
        • ex: port 26379
      • sentinel <option name> <master name> <master IP> <port number> <option value>
        • ex: sentinel monitor mymaster 127.0.0.1 6379 2
      • sentinel down-after-milliseconds <master name> 100
        • ex: sentinel down-after-milliseconds mymaster 100
      • sentinel failover-timeout <master name> 600
        • ex: sentinel failover-timeout mymaster 600
      • sentinel parallel-syncs <master name> <sentinals count>
        • ex: sentinel parallel-syncs mymaster 2

Redis slave changes:

redis.conf

      • port <port number> // for redis server port
        • ex: port 6380
      • slavereadonly no
      • slaveof <master IP> <port number>
        • ex: slaveof 127.0.0.1 6379

sentinel.conf

      • port <port number> // for redis sentinel port
        • ex: port 26380
      • sentinel <option name> <master name> <master IP> <port number> <option value>
        • ex: sentinel monitor mymaster 127.0.0.1 6379 2
      • sentinel down-after-milliseconds <master name> 100
        • ex: sentinel down-after-milliseconds mymaster 100
      • sentinel failover-timeout <master name> 600
        • ex: sentinel failover-timeout mymaster 600
      • sentinel parallel-syncs <master name> <sentinals count>
        • ex: sentinel parallel-syncs mymaster 2

References

Benchmark