Skip to content

Commit

Permalink
test: redis clustering
Browse files Browse the repository at this point in the history
  • Loading branch information
SeungGwan123 committed Dec 1, 2024
1 parent ed0333e commit 54e2da4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
11 changes: 6 additions & 5 deletions packages/server/src/redis/chart-redis.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@ export class ChartRedisRepository {

async getChartDate(keys: string[]): Promise<any[]> {
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);
}
}
}
17 changes: 14 additions & 3 deletions packages/server/src/redis/redis.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down

0 comments on commit 54e2da4

Please sign in to comment.