[英]Redis sentinel connection is timing out from nodeJS
Am trying to connect redis sentinel
instance from nodeJS
using ioredis
.我正在尝试使用
ioredis
从nodeJS
连接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";
"The arguments passed to the constructor are different from the ones you use to connect to a single node" “传递给构造函数的参数与您用于连接到单个节点的参数不同”
Try to replace password
with sentinelPassword
.尝试用
sentinelPassword
替换password
。
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.