refactor(core): Introduce RedisClientService (no-changelog) (#9774)

This commit is contained in:
Iván Ovejero
2024-06-20 12:55:07 +02:00
committed by GitHub
parent 199dff4fb3
commit 7b396e78c6
17 changed files with 231 additions and 223 deletions

View File

@@ -3,7 +3,7 @@ import type { Cluster } from 'ioredis';
import { Service } from 'typedi';
import config from '@/config';
import { Logger } from '@/Logger';
import { getDefaultRedisClient } from './RedisServiceHelper';
import { RedisClientService } from './redis-client.service';
export type RedisClientType =
| 'subscriber'
@@ -29,13 +29,16 @@ class RedisServiceBase {
isInitialized = false;
constructor(protected readonly logger: Logger) {}
constructor(
protected readonly logger: Logger,
private readonly redisClientService: RedisClientService,
) {}
async init(type: RedisClientType = 'client'): Promise<void> {
if (this.redisClient && this.isInitialized) {
return;
}
this.redisClient = await getDefaultRedisClient(undefined, type);
this.redisClient = this.redisClientService.createClient({ type });
this.redisClient.on('close', () => {
this.logger.warn('Redis unavailable - trying to reconnect...');