我有幾個使用redis內(nèi)存存儲的云函數(shù)谷歌兌換代碼時出錯,它給了我這個Redis連接到:6379失敗-在TCP上讀取。每次部署任何函數(shù)時都會出現(xiàn)錯誤。以前,我通過創(chuàng)建一個單獨的文件并將它們包含在of中來與所有函數(shù)共享util ()代碼,我認(rèn)為這就是問題所在。但請注意谷歌兌換代碼時出錯,除了這個錯誤之外,這個Redis緩存工作正常。
然后,我嘗試將util代碼放入使用redis客戶端創(chuàng)建客戶端的每個云函數(shù)中。但是當(dāng)我每次部署任何一個云函數(shù)時,我仍然會從每個云函數(shù)中得到這個錯誤。即使在部署不使用redis的函數(shù)時也是如此。
下面是我創(chuàng)建客戶端的方法:
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);
復(fù)制
為什么我在每個云函數(shù)日志上都看到這個錯誤?
我得到的錯誤日志示例:
API One - Redis cache error : Error: Redis connection to :6379 failed - read ECONNRESET
API Two - Redis cache error : Error: Redis connection to :6379 failed - read ECONNRESET
復(fù)制