`redis.createCluster()` 使用 TLS 连接到 ElastiCache for Redis 时返回 ECONNRESET。

huangapple go评论45阅读模式
英文:

redis.createCluster() with TLS returns ECONNRESET when trying to conenct to ElastiCache for Redis

问题

我正在构建一个使用 node-redis 连接到 ElastiCache Redis 的 Node.js 应用程序,我试图启用传输中的加密。

到目前为止,这是我拥有的代码:

const redis = require('redis');

const socket = {
    host: redisAddress,
    port: redisPort,
    tls: true
}

const redisCluster = redis.createCluster({ rootNodes: [{ socket }] })
redisCluster.connect()

不幸的是,我遇到了以下错误:

UnhandledPromiseRejectionWarning: Error: read ECONNRESET
英文:

I am building a nodejs app that connects to ElastiCache Redis using node-redis. I'm trying to enable encryption-in-transit.

Here is what I have so far:

const redis = require('redis');

const socket = {
    host: redisAddress,
    port: redisPort,
    tls: true
}

const redisCluster = redis.createCluster({ rootNodes: [{ socket }] })
redisCluster.connect()

Unfortunately, I get the following error:

UnhandledPromiseRejectionWarning: Error: read ECONNRESET

答案1

得分: 1

node-redis集群文档中的引用:

  • rootNodes - 一个包含集群的根节点的数组,将用于获取集群拓扑。数组中的每个元素都是客户端配置对象。无需指定集群中的每个节点,通常指定3个根节点就足以可靠地连接并从服务器获取集群配置。

这意味着我们在rootNodes中指定的客户端配置适用于根节点,但不适用于拓扑中的每个节点。您需要像这样指定defaults

  • defaults - 集群中每个客户端的默认配置值。例如,当指定要连接的ACL用户时,请使用此选项。

您的代码最终会看起来像这样:

const redis = require('redis');

const socket = {
    host: redisAddress,
    port: redisPort,
    tls: true
}

const redisCluster = redis.createCluster({
    rootNodes: [{ socket }],
    defaults: { socket: { tls: true } }
})
redisCluster.connect()
英文:

From the node-redis documentation on clustering:
> rootNodes - an array of root nodes that are part of the cluster, which will be used to get the cluster topology. Each element in the array is a client configuration object. There is no need to specify every node in the cluster, 3 should be enough to reliably connect and obtain the cluster configuration from the server

This means that the client configuration we specify in rootNodes applies to the root nodes, but not for each and every node in the topology. What you want to do is to specify defaults as well.

> defaults - The default configuration values for every client in the cluster. Use this for example when specifying an ACL user to connect with

Your code will end up looking something like:

const redis = require('redis');

const socket = {
    host: redisAddress,
    port: redisPort,
    tls: true
}

const redisCluster = redis.createCluster({
    rootNodes: [{ socket }],
    defaults: { socket: { tls: true } }
})
redisCluster.connect()

huangapple
  • 本文由 发表于 2023年2月27日 04:00:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/75574672.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定