Read from slaves with replication
See original GitHub issueHi,
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) ofA
(localhost). - Node
C
slave (replica) ofA
(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) {
console.log(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:
- Created 7 years ago
- Reactions:1
- Comments:15 (6 by maintainers)
Top 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 - Educative.io
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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.@dev-drprasad That’s supported in the cluster mode. Otherwise, you may refer to @toredash 's approach.