Implementing Redis Sentinel

1. Understanding Sentinel Architecture

   ┌──────────┐  monitors  ┌──────────┐
   │ Sentinel │ ─────────▶ │  Master  │
   └────┬─────┘            └────┬─────┘
        │ quorum                │ replicates
        ▼                       ▼
   ┌──────────┐            ┌──────────┐
   │ Sentinel │ ─────────▶ │ Replica  │
   └──────────┘            └──────────┘
   ┌──────────┐
   │ Sentinel │  (≥3 for safe failover decisions)
   └──────────┘
      
RoleFunction
MonitoringDetect master/replica failure
NotificationPub/Sub events for operators
FailoverPromote replica, reconfigure others
Configuration providerClients discover current master

2. Configuring Sentinel Instances

port 26379
sentinel monitor mymaster 10.0.0.1 6379 2
sentinel auth-pass mymaster secret
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1

3. Monitoring Master Instances

DirectiveDescription
sentinel monitor <name> host port quorumRegister master + quorum size

4. Setting Quorum Requirements

AspectDetail
QuorumSentinels needed to agree master is down (subjective→objective)
MajoritySentinels needed to authorize failover (always majority of total)

5. Configuring Automatic Failover

DirectiveDescription
failover-timeoutMax time per failover phase
parallel-syncsReplicas reconfigured concurrently

6. Configuring Down-After-Milliseconds

DirectiveDefault
down-after-milliseconds30000 — time without PONG to mark SDOWN

7. Understanding Parallel-Syncs Setting

ValueTradeoff
1Safe; replicas resync one at a time
>1Faster but uses more master bandwidth

8. Getting Sentinel Info

CommandDescription
SENTINEL MASTERSAll monitored masters
SENTINEL MASTER <name>Single master detail
SENTINEL REPLICAS <name>List replicas
SENTINEL SENTINELS <name>Peer sentinels

9. Getting Master Address

CommandReturns
SENTINEL GET-MASTER-ADDR-BY-NAME <name>[ip, port]

10. Manual Failover

CommandDescription
SENTINEL FAILOVER <name>Force failover (no quorum check)
SENTINEL RESET patternReset state for matching masters

11. Adding and Removing Sentinels

ActionMethod
AddStart new sentinel with matching monitor line; auto-discovers peers
RemoveStop sentinel; SENTINEL RESET on peers

12. Monitoring Sentinel Events

Event ChannelMeaning
+sdown / -sdownSubjectively down / restored
+odownObjectively down (quorum reached)
+switch-masterFailover completed
+slaveNew replica discovered