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
Answering this for the benefit of others. Everything is fine, but this
nodeJS
package is resolvingredis
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."The arguments passed to the constructor are different from the ones you use to connect to a single node"
Try to replace
password
withsentinelPassword
.