简体   繁体   English

Redis 哨兵连接从 nodeJS 超时

[英]Redis sentinel connection is timing out from nodeJS

Am trying to connect redis sentinel instance from nodeJS using ioredis .我正在尝试使用ioredisnodeJS连接redis sentinel实例。 Am not able to connect redis sentinel instance despite trying multiple available options.尽管尝试了多个可用选项,但仍无法连接 redis 哨兵实例。 We have not configured sentinel password.我们还没有配置哨兵密码。 But, able to connect same redis sentinel instance from .net core using StackExchange.Redis .但是,能够使用StackExchange.Redis.net core连接相同的 redis 哨兵实例。 Please find below nodeJS code,请在下面找到nodeJS代码,

import { AppModule } from './app.module';
import IORedis from 'ioredis';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const ioredis = new IORedis({
    sentinels: [
      { host: 'sentinel-host-1' },
      { host: 'sentinel-host-2' },
      { host: 'sentinel-host-3' },
    ],
    name: 'mastername',
    password: 'password',
    showFriendlyErrorStack: true,
  });
  try {
    ioredis.set('foo', 'bar');
  } catch (exception) {
    console.log(exception);
  }
  await app.listen(3000);
}
bootstrap();

Error we got is,我们得到的错误是,

[ioredis] Unhandled error event: Error: connect ETIMEDOUT
node_modules\ioredis\built\redis\index.js:317:37)
    at Object.onceWrapper (node:events:475:28)
    at Socket.emit (node:events:369:20)
    at Socket._onTimeout (node:net:481:8)
    at listOnTimeout (node:internal/timers:557:17)
    at processTimers (node:internal/timers:500:7)

Connection String used from .net core is below,.net core使用的连接字符串如下,

Redis_Configuration = "host-1,host-2,host-3,serviceName=mastername,password=password,abortConnect=False,connectTimeout=1000,responseTimeout=1000";

Answering this for the benefit of others.回答这个是为了他人的利益。 Everything is fine, but this nodeJS package is resolving redis instances into private IPs which i cannot access from my local.一切都很好,但是这个nodeJS包正在将redis实例解析为我无法从本地访问的私有 IP。 So, had to put it over subnet group and make it work.因此,必须将它放在子网组上并使其工作。 However, FYI - .net core package does not resolve into private IPs, hence i was able to access instances from my local itself.但是,仅供参考 - .net core包不会解析为私有 IP,因此我能够从本地访问实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM