From 54e2da4919e5ad83ce72831f5727245c3e773d4d Mon Sep 17 00:00:00 2001 From: SeungGwa123 Date: Sun, 1 Dec 2024 22:28:30 +0900 Subject: [PATCH] test: redis clustering --- .../server/src/redis/chart-redis.repository.ts | 11 ++++++----- packages/server/src/redis/redis.module.ts | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/server/src/redis/chart-redis.repository.ts b/packages/server/src/redis/chart-redis.repository.ts index 40f88fc2..9e964f33 100644 --- a/packages/server/src/redis/chart-redis.repository.ts +++ b/packages/server/src/redis/chart-redis.repository.ts @@ -13,19 +13,20 @@ export class ChartRedisRepository { async getChartDate(keys: string[]): Promise { try { - const promises = keys.map((key) => this.chartRedis.get(key)); - const results = await Promise.all(promises); - return results.map((data) => (data ? JSON.parse(data) : null)).filter((data) => data !== null); + const results = await Promise.all(keys.map((key) => this.getSimpleChartData(key))); + return results.filter((data) => data !== false); } catch (error) { console.error('DB Searching Error:', error); throw error; } } - + async getSimpleChartData(key) { const data = await this.chartRedis.get(key); if (!data) { return false; - } else return JSON.parse(data); + } else { + return JSON.parse(data); + } } } diff --git a/packages/server/src/redis/redis.module.ts b/packages/server/src/redis/redis.module.ts index 43f81157..b3c732e8 100644 --- a/packages/server/src/redis/redis.module.ts +++ b/packages/server/src/redis/redis.module.ts @@ -38,11 +38,22 @@ import { ChartRedisRepository } from './chart-redis.repository'; provide: 'CHART_REDIS_CLIENT', useFactory: () => { const config = getRedisConfig(); - const client = new Redis({ ...config, db: 3 }); + const client = new Redis.Cluster([ + { host: 'node1-host', port: 6379 }, + { host: 'node2-host', port: 6379 }, + { host: 'node3-host', port: 6379 }, + // Add more nodes as needed + ], { + scaleReads: 'all', + redisOptions: { + password: config.password, + db: 3 + } + }); const logger = new Logger('CHART_REDIS_CLIENT'); - client.on('connect', () => logger.log('Chart용 Redis 연결 성공')); + client.on('connect', () => logger.log('Chart용 Redis 클러스터 연결 성공')); client.on('error', (error) => - logger.error('Chart용 Redis 연결 실패:', error), + logger.error('Chart용 Redis 클러스터 연결 실패:', error), ); return client; },