首先,让我告诉您如何在 NodeJS 应用程序中使用 Redis 连接:
class RDB {
static async getClient() {
if (this.client) {
return this.client
}
let startTime = Date.now();
this.client = createClient({
url: config.redis.uri
});
await this.client.connect();
return this.client;
}
}
Run Code Online (Sandbox Code Playgroud)
由于某种原因 - 我不知道 - 我的应用程序有时会崩溃,无缘无故地出现错误 - 这种情况大约每周发生一两次:
Error: Socket closed unexpectedly
Run Code Online (Sandbox Code Playgroud)
现在,我的问题是: