skip to Main Content

Am trying to connect redis sentinel instance from nodeJS using ioredis. Am not able to connect redis sentinel instance despite trying multiple available options. We have not configured sentinel password. But, able to connect same redis sentinel instance from .net core using StackExchange.Redis. Please find below nodeJS code,

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_modulesioredisbuiltredisindex.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,

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

2

Answers


  1. Chosen as BEST ANSWER

    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. 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.


Please signup or login to give your own answer.
Back To Top
Search