我正在 Amazon EKS 上运行 Node.js 应用程序,该应用程序连接到配置为单节点集群的 Amazon Elastic Cache Redis 实例(节点类型:cache.t3.micro)。安全规则配置正确,应用程序在运行少量 Pod(4 到 10 个之间)时可以成功连接到 Redis。然而,当将应用程序扩展到 20-30 个 Pod 时,我开始遇到 Redis 连接超时错误。
以下是用于在我的 Node.js 应用程序中建立 Redis 连接的代码片段:
const redisClient = require("redis");
const initRedisClient = async () => {
try {
info(`connecting to redis client`);
let connectionClient = redisClient.createClient({
url : `redis://${redisUrl}:6379`
});
connectionClient.on("error",(err) => {
console.log("error",err);
throw new Error(err?.message);
});
connectionClient.on("connect",function () {
console.log("redis connected successfully!");
// storeData("WAIT_TIME","5",false,0);
// storeData("BUFFER_TIME","2",false,0);
})
await connectionClient.connect();
client = connectionClient;
return client;
} catch (error) {
console.log(error?.message);
console.log(error?.message);
return {
type : "error",
message : error?.message
};
}
}
收到的错误消息与连接超时有关。但是,初始连接或 pod 数量较少没有问题。
任何有关如何排查和解决此问题的见解或建议将不胜感激。
你能找到解决方案吗?我也面临着同样的问题,但在 EKS 中