How to make Python failover to Redis slave if master is down?
With current configuration, Sentinels elect a new master, but Python writes stop.
I assume I should not use redis-master as is in docker-compose.yml file; what are the alternatives?
In networking mode, I couldn't get Sentinels to recognize each other.
docker-compose.yml
version: '3'
services:
redis-master:
container_name: redis-master
image: redis:latest
command: redis-server --port 6379
ports:
- "6379:6379"
volumes:
- .:/app
redis-slave:
container_name: redis-slave
image: redis:latest
command: redis-server --slaveof redis-master 6379 --protected-mode no
volumes:
- .:/app
sentinel-1:
container_name: sentinel-1
build: sentinel
environment:
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
sentinel-2:
container_name: sentinel-2
build: sentinel
environment:
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
sentinel-3:
container_name: sentinel-3
build: sentinel
environment:
- SENTINEL_DOWN_AFTER=5000
- SENTINEL_FAILOVER=5000
app:
container_name: python-app
image: pyredis
command: python app.py
Python app:
import redis
import random
import time
r = redis.StrictRedis(host="redis-master", port=6379, db=0)
for i in range(0, 1000):
timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
num = random.randint(1,101)
r.set(timestamp, num)
time.sleep(2)
Thank you, any input is appreciated.