Redis Sentinel provides high availability for Redis when not using Redis Cluster. Sentinel constantly checks if your master and replica instances are working as expected. If a master is not working as expected, Sentinel can start a failover process where a replica is promoted to master, the other additional replicas are reconfigured to use the new master, and the applications using the Redis server are informed about the new address to use when connecting. If a failover occurs, Sentinels will report the new master address.


Architecture

Redis Sentinel Architecture

You need at least three Sentinel instances for a robust deployment.

  • Redis Master: Primary node that handles write operations
  • Redis Replicas: Secondary nodes that replicate data from the master
  • Sentinel Nodes: Monitor Redis instances and perform failover operations

Configuration


Redis Configuration

Parameter Description
replica-announce-ip <hostname> Hostname announced by replica to master
replicaof <hostname> 6379 Specifies master hostname and port for replication

Configure Redis Master

Edit /etc/redis/redis.conf on the master server:

replica-announce-ip <replica-hostname>

Configure Redis Replica

Edit /etc/redis/redis.conf on the replica server:

replica-announce-ip <replica-hostname>
replicaof <master-hostname> 6379

Sentinel Configuration

Parameter Description
sentinel resolve-hostnames yes Enables DNS resolution for hostnames
sentinel announce-hostnames yes Uses hostnames instead of IPs when announcing Sentinel instance
sentinel monitor mymaster <hostname> 6379 2 Monitors Redis master at specified hostname on port 6379; requires 2 sentinels to agree before failover
sentinel announce-ip <hostname> Specifies the hostname that Sentinel announces to clients

Configure Sentinel Servers

Edit /etc/redis/sentinel.conf on each Sentinel server:

sentinel resolve-hostnames yes
sentinel announce-hostnames yes
sentinel monitor mymaster <master-hostname> 6379 2
sentinel announce-ip <sentinel-hostname>

Start Services

Start Redis on master and replicas:

sudo systemctl restart redis

Start Sentinel on each Sentinel server:

sudo systemctl restart redis-sentinel

Testing Failover

To test failover capabilities:

  1. Shut down the master instance:

    sudo systemctl stop redis-server
  2. Monitor Sentinel logs to observe failover:

    redis-cli -p 26379
    > SENTINEL masters
  3. Check which node is the new master:

    redis-cli -h <any-redis-node> -p 6379 info replication

Here, a robust and highly available Redis is running with Redis Sentinel.