【发布时间】:2019-09-09 10:21:05
【问题描述】:
我有一些使用 redis 内存存储的谷歌云功能,它给了我这个 Redis 连接到:6379 failed - 在 TCP 上读取 ECONNRESET。每次部署任何功能时都会出现 onread 错误。以前,我通过创建一个单独的 util 文件并将它们包含在 CF 中来与所有函数共享 createClient() 代码,我认为这就是问题所在。但请注意,除了此错误之外,此 Redis 缓存正在按预期工作。
然后我尝试将 util 代码放入每个使用 redis 客户端创建客户端的谷歌云函数中。但是,当我每次部署任何云功能时,我仍然会从每个云功能中收到此错误。即使在部署不使用redis的功能时。
这是我创建客户端的方法:
const bluebird = require('bluebird');
const redis = bluebird.promisifyAll(require('redis'));
const cache = redis.createClient({ port: REDIS_PORT, host: REDIS_HOST });
cache.on("error", (err) => {
console.log("API One - Redis cache error : " + err);
});
const list = async(data) => {
// Do something with data.
let cachedData;
if(cache.connected) {
await cache.hgetAsync(key); // Get cached Data.
}
// Do something with cached data if cachedData available.
if(cache.connected) {
await cache.hsetAsync(key, data); // Set Some Data.
}
return data;
}
module.exports = functions.https.onCall(list);
为什么我在每个云功能日志中都看到此错误?
我得到的示例错误日志:
API One - Redis cache error : Error: Redis connection to <Ip Address>:6379 failed - read ECONNRESET
API Two - Redis cache error : Error: Redis connection to <Ip Address>:6379 failed - read ECONNRESET
【问题讨论】:
标签: javascript redis async-await google-cloud-functions