Quantcast
Channel: StackExchange Replication Questions
Viewing all articles
Browse latest Browse all 17268

How to initialize Redis client to write to master and read from slaves

$
0
0

Supposing I have a replicated master-slave Redis setup, how do I actually access it from a client library? Presumably I need a client instance per each host and I need to decide which I want to use for writing and reading, like:

master = redis.Redis(master_host, port)
clients = [redis.Redis(host, port) for host in slave_hosts]

master.set('key', 'value')
client = random.choice(clients)
client.get('other-key')

I was thinking there should be some magic in the library where I could provide a list of hosts for making such routing automatic, but couldn't find it.

I've also looked into redis-cluster and redis-sentinel and they all start by talking about automatic failovers when slaves become masters, and I'm not sure it's what I need. What I need is a consistent master which I can afford to lose for some time (I can hold up updates in a queue).


Viewing all articles
Browse latest Browse all 17268

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>