1 個回答
- 最新
- 最多得票
- 最多評論
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.
已回答 1 年前
相關內容
- 已提問 6 個月前
- AWS 官方已更新 2 年前
- AWS 官方已更新 2 年前
- AWS 官方已更新 7 個月前
- AWS 官方已更新 2 年前