At My work project We are using ioredis client for a Redis Sentinel Cluster with 2 Slaves and a Master and We’re trying to send write commands to the Master and read ones to a specific Slave for each of our microservices. but as I was searching, the only viable solution I found was in a closed github issue of the ioredis itself which suggested to use separate clients for each operation and that this separation is only supported for Redis Clusters with the “scaleReads” option.
So, My Question is, is there a better solution for this issue?
Link to the github issue:
https://github.com/redis/ioredis/issues/387
Example:
var redis_ro = new Redis({
sentinels: [{ host: '127.0.0.1', port: 26379 }, { host: '127.0.0.1', port: 26380 }],
name: 'mymaster',
role: 'slave',
preferredSlaves: [
{ ip: "127.0.0.1", port: "31231", prio: 1 },
{ ip: "127.0.0.1", port: "31232", prio: 2 },
]
});
var redis = new Redis({
sentinels: [{ host: '127.0.0.1', port: 26379 }, { host: '127.0.0.1', port: 26380 }],
name: 'mymaster'
});