Implementing Redis Sentinel
1. Understanding Sentinel Architecture
┌──────────┐ monitors ┌──────────┐
│ Sentinel │ ─────────▶ │ Master │
└────┬─────┘ └────┬─────┘
│ quorum │ replicates
▼ ▼
┌──────────┐ ┌──────────┐
│ Sentinel │ ─────────▶ │ Replica │
└──────────┘ └──────────┘
┌──────────┐
│ Sentinel │ (≥3 for safe failover decisions)
└──────────┘
| Role | Function |
|---|---|
| Monitoring | Detect master/replica failure |
| Notification | Pub/Sub events for operators |
| Failover | Promote replica, reconfigure others |
| Configuration provider | Clients 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
| Directive | Description |
|---|---|
sentinel monitor <name> host port quorum | Register master + quorum size |
4. Setting Quorum Requirements
| Aspect | Detail |
|---|---|
| Quorum | Sentinels needed to agree master is down (subjective→objective) |
| Majority | Sentinels needed to authorize failover (always majority of total) |
5. Configuring Automatic Failover
| Directive | Description |
|---|---|
failover-timeout | Max time per failover phase |
parallel-syncs | Replicas reconfigured concurrently |
6. Configuring Down-After-Milliseconds
| Directive | Default |
|---|---|
down-after-milliseconds | 30000 — time without PONG to mark SDOWN |
7. Understanding Parallel-Syncs Setting
| Value | Tradeoff |
|---|---|
| 1 | Safe; replicas resync one at a time |
| >1 | Faster but uses more master bandwidth |
8. Getting Sentinel Info
| Command | Description |
|---|---|
SENTINEL MASTERS | All monitored masters |
SENTINEL MASTER <name> | Single master detail |
SENTINEL REPLICAS <name> | List replicas |
SENTINEL SENTINELS <name> | Peer sentinels |
9. Getting Master Address
| Command | Returns |
|---|---|
SENTINEL GET-MASTER-ADDR-BY-NAME <name> | [ip, port] |
10. Manual Failover
| Command | Description |
|---|---|
SENTINEL FAILOVER <name> | Force failover (no quorum check) |
SENTINEL RESET pattern | Reset state for matching masters |
11. Adding and Removing Sentinels
| Action | Method |
|---|---|
| Add | Start new sentinel with matching monitor line; auto-discovers peers |
| Remove | Stop sentinel; SENTINEL RESET on peers |
12. Monitoring Sentinel Events
| Event Channel | Meaning |
|---|---|
+sdown / -sdown | Subjectively down / restored |
+odown | Objectively down (quorum reached) |
+switch-master | Failover completed |
+slave | New replica discovered |