Skip to content

Commit

Permalink
fix: stop crashing when redis is offline and ignoreErrors on cache op…
Browse files Browse the repository at this point in the history
…tions is set (#8725)

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
  • Loading branch information
mesinger and pleerock authored Mar 26, 2022
1 parent ceee439 commit edc39d1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/cache/RedisQueryResultCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,20 @@ export class RedisQueryResultCache implements QueryResultCache {
/**
* Creates a connection with given cache provider.
*/

async connect(): Promise<void> {
const cacheOptions: any = this.connection.options.cache
if (this.clientType === "redis") {
this.client = this.redis.createClient({
...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) {
Expand Down

0 comments on commit edc39d1

Please sign in to comment.