from redis.sentinel import Sentinel
# This way you can connect to a REDIS cluster via its sentinels
sentinel = Sentinel([('SENTINEL-1', 26379),
('SENTINEL-2', 26379),
('SENTINEL-3', 26379)],
socket_timeout=1, password="password", decode_responses=True)
# Get the current main
main = sentinel.master_for('main_key', socket_timeout=1)
# Get the current subordinates
subordinate = sentinel.slave_for('main_key', socket_timeout=1)
# Set some key on the main
# Writes work only on main
main.set("Py_key1", "hello")
# Read/Get the key from a Subordinate
test = subordinate.get("Py_key1")
print (test)
# Delete a key on the active (main)
main.delete("Py_key1")