1 Answer
- Newest
- Most votes
- Most comments
0
When connecting to Redis with cluster mode enabled, many clients will try to connect to all cluster nodes on initialization. The replica node(s) will not be reachable given the network setup that you have described. If you disable this behaviour of pre-connecting to all nodes, you should be able to successfully connect to the individual node that you have opened a tunnel onto.
Here is an example of how to connect without attempting to connect to all nodes, using the popular ioredis library:
let Redis = require('ioredis');
let cluster = new Redis.Cluster([{
host: 'localhost',
port: 6378
}], {
lazyConnect: true
});
async function main() {
await cluster.set("foo", "bar");
console.log(await cluster.get("foo"));
cluster.disconnect();
}
main();
NB: If more than one shard was setup in the cluster, this method would experience issues when hitting a shard on a different node to the node that you have tunnelled to.
answered 2 years ago
Relevant content
- asked 6 years ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 3 months ago