Skip to content

Commit 0e91a61

Browse files
committed
feature: module 하위 test 디렉토리 분리, cache index 추가
1 parent 2b4e3fd commit 0e91a61

File tree

7 files changed

+53
-0
lines changed

7 files changed

+53
-0
lines changed

.env.sample

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,14 @@ POSTGRES_PASSWORD=vd2
2121
POSTGRES_HOST=localhost
2222
POSTGRES_PORT=5432
2323

24+
# Cache (redis)
25+
REDIS_HOST=localhost
26+
REDIS_PORT=6379
27+
REDIS_PASSWORD=notion-check-plz
28+
REDIS_DB=0
29+
REDIS_KEY_PREFIX=vd2:cache:
30+
CACHE_DEFAULT_TTL=300
31+
2432
# Slack Notification
2533
SLACK_WEBHOOK_URL=https://hooks.slack.com/services
2634

src/modules/cache/__test__/redis.cache.test.ts

Whitespace-only changes.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import logger from '@/configs/logger.config';
2+
3+
import { ICache, CacheConfig } from './cache.type';
4+
import { RedisCache } from "./redis.cache";
5+
6+
7+
const cacheConfig: CacheConfig = {
8+
host: process.env.REDIS_HOST || '152.67.198.7',
9+
port: parseInt(process.env.REDIS_PORT || '6379'),
10+
password: process.env.REDIS_PASSWORD || 'velog-dashboard-v2-cache!@#!@#123',
11+
db: parseInt(process.env.REDIS_DB || '0'),
12+
keyPrefix: process.env.REDIS_KEY_PREFIX || 'vd2:cache:',
13+
defaultTTL: parseInt(process.env.CACHE_DEFAULT_TTL || '300'), // 5분
14+
};
15+
16+
// 싱글톤 캐시 인스턴스 (const로 변경하고 null 초기화)
17+
const cacheInstance: ICache = new RedisCache(cacheConfig);
18+
19+
export const cache = cacheInstance;
20+
21+
// 초기화 함수
22+
export const initCache = async (): Promise<void> => {
23+
try {
24+
await cache.connect();
25+
logger.info('Cache system initialized successfully');
26+
} catch (error) {
27+
logger.error('Failed to initialize cache system:', error);
28+
// 캐시 연결 실패해도 애플리케이션은 계속 실행
29+
logger.warn('Application will continue without cache');
30+
}
31+
};
32+
33+
// 종료 함수
34+
export const closeCache = async (): Promise<void> => {
35+
try {
36+
await cache.disconnect();
37+
logger.info('Cache system closed successfully');
38+
} catch (error) {
39+
logger.error('Failed to close cache system:', error);
40+
}
41+
};

src/modules/cache/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './cache.type';
2+
export { cache } from './cache.instance';
3+
export { initCache, closeCache } from './cache.instance';
4+
export { RedisCache } from './redis.cache';
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)