使用node.js ioredis连接到azure redis群集不起作用

6qftjkof  于 2021-06-09  发布在  Redis
关注(0)|答案(1)|浏览(640)

我一直在尝试使用ioredis连接到azure中的redis三节点集群。
当我使用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为我提供了一个主机+端口组合和两个不同的访问密钥(主/辅)-我觉得很奇怪,我应该使用哪个访问密钥?我也不确定我是否应该在集群模式下连接,但我更愿意获得集群的好处。当我这样做时,它似乎试图在 127.0.0.1:6380 这可能是不正确的。
在azure的快速启动中,他们使用节点\u 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}});

我希望这里的人也能遇到同样的问题并解决它。
谢谢!

ltqd579y

ltqd579y1#

好的,我已经使用非tls连接成功连接到azure redis群集:

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

由于某些原因,在启用tls的情况下连接到6380不起作用。

相关问题