Database Management
Redis
Subjective
Oct 05, 2025
Explain Redis Sentinel for high availability setup.
Detailed Explanation
Redis Sentinel provides high availability and monitoring:
**Architecture:**
• Monitors master and replica instances
• Automatic failover when master fails
• Configuration provider for clients
• Notification system for events
**Sentinel Configuration:**
# sentinel.conf
port 26379
sentinel monitor mymaster 192.168.1.100 6379 2
sentinel auth-pass mymaster your_password
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 10000
sentinel parallel-syncs mymaster 1
**Client Connection (Python):**
from redis.sentinel import Sentinel
# Connect to Sentinels
sentinel = Sentinel([
('192.168.1.100', 26379),
('192.168.1.101', 26379),
('192.168.1.102', 26379)
], socket_timeout=0.1)
# Get master and replica connections
master = sentinel.master_for('mymaster', socket_timeout=0.1)
replica = sentinel.slave_for('mymaster', socket_timeout=0.1)
# Use connections
master.set('key', 'value') # Write to master
value = replica.get('key') # Read from replica
**Monitoring Commands:**
# Sentinel status
redis-cli -p 26379 SENTINEL masters
redis-cli -p 26379 SENTINEL slaves mymaster
# Manual failover
redis-cli -p 26379 SENTINEL failover mymaster
**Best Practices:**
• Deploy odd number of Sentinels (3, 5, 7)
• Distribute Sentinels across different servers
• Set appropriate timeouts
• Monitor Sentinel logs
• Test failover scenarios regularly
Discussion (0)
No comments yet. Be the first to share your thoughts!
Share Your Thoughts