node.js - 使用 node.js ioredis 连接到 Azure Redis 集群不起作用

标签 node.js azure redis ioredis

我一直在尝试使用 ioredis 连接到 Azure 中的 Redis 三 Node 集群.

当我使用 Redis.Cluster 构造函数进行连接时:

new Redis.Cluster(['host.redis.cache.windows.net', 6380], {
    scaleReads: 'all',
    slotsRefreshTimeout: 2000,
    redisOptions: {
        password: 'some-secret',
        tls: true as any
    },
});

我得到的错误是:

2020-06-04T13:05:41.787Z ioredis:cluster getting slot cache from 127.0.0.1:6380
2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: [empty] -> wait
2020-06-04T13:05:41.788Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: wait -> connecting
2020-06-04T13:05:41.788Z ioredis:redis queue command[127.0.0.1:6380 (ioredisClusterRefresher)]: 0 -> cluster([ 'slots' ])
2020-06-04T13:05:41.790Z ioredis:connection error: Error: connect ECONNREFUSED 127.0.0.1:6380
2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: connecting -> close
2020-06-04T13:05:41.791Z ioredis:connection skip reconnecting because `retryStrategy` is not a function
2020-06-04T13:05:41.791Z ioredis:redis status[127.0.0.1:6380 (ioredisClusterRefresher)]: close -> end
2020-06-04T13:05:41.792Z [auth-middleware] Redis error { ClusterAllFailedError: Failed to refresh slots cache.
    at tryNode (/app/node_modules/ioredis/built/cluster/index.js:359:31)
    at /app/node_modules/ioredis/built/cluster/index.js:376:21
    at duplicatedConnection.cluster.utils_2.timeout (/app/node_modules/ioredis/built/cluster/index.js:624:24)
    at run (/app/node_modules/ioredis/built/utils/index.js:156:22)
    at tryCatcher (/app/node_modules/standard-as-callback/built/utils.js:11:23)
    at promise.then (/app/node_modules/standard-as-callback/built/index.js:30:51)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  lastNodeError:
   Error: Connection is closed.
       at close (/app/node_modules/ioredis/built/redis/event_handler.js:179:25)
       at TLSSocket.<anonymous> (/app/node_modules/ioredis/built/redis/event_handler.js:150:20)
       at Object.onceWrapper (events.js:277:13)
       at TLSSocket.emit (events.js:194:15)
       at _handle.close (net.js:600:12)
       at TCP.done (_tls_wrap.js:388:7) }

当我使用非集群 Redis 连接进行连接时:

new Redis(6380, 'host.redis.cache.windows.net', { password: 'some-secret' });

我得到的错误是:

020-06-04T15:04:08.609Z ioredis:redis status[10.211.x.x:6380]: connecting -> connect
2020-06-04T15:04:08.614Z ioredis:redis write command[10.211.x.x:6380]: 0 -> auth([ 'some-secret' ])
2020-06-04T15:04:08.616Z ioredis:redis write command[10.211.x.x:6380]: 0 -> info([])
2020-06-04T15:05:16.114Z ioredis:connection error: Error: read ECONNRESET
2020-06-04T15:05:16.115Z [auth-middleware] Redis error { Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' }

正如您所看到的,它在端口 6380 上使用 TLS。Azure 为我提供了一个主机+端口组合和两个不同的访问 key (主要/次要) - 我觉得这很奇怪,我应该使用哪个访问 key ?另外,我不确定是否应该以集群模式进行连接,但我更愿意获得集群的好处。当我这样做时,它似乎试图在 127.0.0.1:6380 处找到插槽,这可能不正确。

在 Azure 中 quickstart他们使用node_redis连接:

var redis = require("redis");

// Add your cache name and access key.
var client = redis.createClient(6380, process.env.REDISCACHEHOSTNAME,
    {auth_pass: process.env.REDISCACHEKEY, tls: {servername: process.env.REDISCACHEHOSTNAME}});

我希望这里有人遇到同样的问题并解决它。

谢谢!

最佳答案

好的,我已成功使用非 tls 连接连接到 Azure Redis 集群:

new Redis.Cluster(['host.redis.cache.windows.net', 3679], {
    scaleReads: 'all',
    slotsRefreshTimeout: 2000,
    redisOptions: {
      password: 'some-secret',
    },
})

由于某种原因,无法在启用 TLS 的情况下连接到 6380。

关于node.js - 使用 node.js ioredis 连接到 Azure Redis 集群不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62215229/

相关文章:

visual-studio - 可以通过SSMS访问SQL数据库,但不能通过VS2013

java - 如何修复 docker-compose 中 Jedis 中的连接被拒绝错误?

node.js - Node Js : Redis job is not completing after finish its task

node.js - 如何在node js中随机生成objectid

javascript - Node js如何有前导句路径?

git - Phonegap 使用命令行工具添加插件

python - 如何从 python 和 rust 存储和读取 redis 中的公共(public)数据?

javascript - .NET ServerVariables ("AUTH_USER") 和一个非 ASP 页面

javascript - 用 JavaScript 下载 Blob

azure - 我可以为 Azure Blob 存储中的单个文件拥有多个共享访问签名吗?