Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Read from slaves with replication

See original GitHub issue


I’m planning to use ioredis with redis-connect for a distributed express application with consistent sessions.

My doubt, after reading the docs, I’ve assumed the following:

  • Clustering is not needed for session storage, the data won’t be enough big.
  • The majority of the operations will be reads in order to transform cookies into a req.session.

having the following nodes:

  • Node A master (with a known ip).
  • Node B slave (replica) of A (localhost).
  • Node C slave (replica) of A (other node, unknown ip).

I can not perform write operations to B, even if I set slave-read-only to no, the updates won’t propagate, I need to write to A, so…

var Redis = require('ioredis');
var redis = new Redis('a-ip', port);

redis.set('foo', 'bar');
redis.get('foo', function (err, result) {

The ideal behavior would be, I am node B, I open a session, so I go A and set it, then the client comes in again, and I have to identify the cookie, so I read from B (localhost). Is this possible?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

luincommented, Aug 21, 2017

@toredash It depends on what you think is read-write splitting. The discussions above consider “read-write splitting” as an automatic way to send different commands to different nodes via ONE Redis instance. Your example works, while developers have to do the splitting themselves.

luincommented, Jun 30, 2018

@dev-drprasad That’s supported in the cluster mode. Otherwise, you may refer to @toredash 's approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MySQL Master-Slave Replication on the Same Machine - Toptal
As the master-slave replication is a one-way replication (from master to slave), only the master database is used for the write operations, while...
Read more >
Data replication: Master-Slave -
When a client wants to read from the database, it can query either the master or any of the slaves. However, writes are...
Read more >
MySQL replication - how to read from slaves? manually?
I see how to setup replication which looks relatively simple, but I haven't seen how an application should communicate to slaves. I assume...
Read more >
MySQL Master Slave Replication: 7 Easy Steps - Hevo Data
The data is stored in the master first and then copied on to the slaves. Hence, the write operation is performed only on...
Read more >
Master-slave replication database concept for beginners
Binary log has to be read each time data is copied — Each slave adds load to the master as the binary log...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found