From edc39d14a97d90c534b56693b988a0ad139e69fd Mon Sep 17 00:00:00 2001 From: matt Date: Sat, 26 Mar 2022 16:16:32 +0100 Subject: [PATCH] fix: stop crashing when redis is offline and ignoreErrors on cache options is set (#8725) Co-authored-by: Umed Khudoiberdiev --- src/cache/RedisQueryResultCache.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cache/RedisQueryResultCache.ts b/src/cache/RedisQueryResultCache.ts index d6fab6aa31..1e6c137d2a 100644 --- a/src/cache/RedisQueryResultCache.ts +++ b/src/cache/RedisQueryResultCache.ts @@ -47,7 +47,6 @@ export class RedisQueryResultCache implements QueryResultCache { /** * Creates a connection with given cache provider. */ - async connect(): Promise { const cacheOptions: any = this.connection.options.cache if (this.clientType === "redis") { @@ -55,8 +54,13 @@ export class RedisQueryResultCache implements QueryResultCache { ...cacheOptions?.options, legacyMode: true, }) - if ("connect" in this.client) { - await this.client.connect() + if ( + typeof this.connection.options.cache === "object" && + this.connection.options.cache.ignoreErrors + ) { + this.client.on("error", (err: any) => { + this.connection.logger.log("warn", err) + }) } } else if (this.clientType === "ioredis") { if (cacheOptions && cacheOptions.port) {