feat(server): add Redis infrastructure, RedisService, IoAdapter, bookmark caching, and unit tests#45
Merged
Merged
Conversation
…vice, and BookmarkGateway
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
개요
apps/server에 Redis 인프라를 도입하고, 이를 기반으로 Socket.io 어댑터 교체 및 북마크 서비스 캐싱을 적용.Redis 기반 pub/sub 구조로 다중 서버 인스턴스 간 Socket.io 이벤트 브로드캐스트를 지원하며, 북마크 트리 조회 응답속도 개선 및 heartbeat 주기 관리를 Redis로 위임.
관련 서비스·게이트웨이의 단위 테스트를 전면 업데이트하여 캐싱 경로와 fallback 시나리오를 검증.
작업 내용
1. Redis 인프라 구축 (chore)
ioredis,@socket.io/redis-adapter의존성 설치 (apps/server/package.json).REDIS_HOST,REDIS_PORT항목을apps/server/.env.example및env.validation.ts의 Zod 스키마에 추가.redis서비스 컨테이너 정의 추가 — 포트 매핑, 재시작 정책 설정.2. RedisService 및 RedisIoAdapter 구현 (feat)
redis.service.ts:ioredis클라이언트를 래핑한 NestJS 서비스.get,set,del,publish,subscribe등의 기본 연산 제공. TTL 옵션 지원.onModuleDestroy에서 연결 정리.redis.module.ts:RedisService를 전역 모듈로 등록하여 어디서든 주입 가능하도록 설정.redis-io.adapter.ts:@socket.io/redis-adapter기반 커스텀 어댑터 구현.main.ts에서 기존 기본 어댑터를 대체하여 다중 인스턴스 환경에서 이벤트 브로드캐스트 일관성 보장.3. 북마크 서비스 캐싱 및 게이트웨이 heartbeat 적용 (feat)
bookmark.service.ts: 북마크 트리 조회 시 Redis 캐시 hit/miss 분기 처리. 캐시 miss 시 DB 조회 후 직렬화하여 TTL과 함께 저장. 북마크 변경(생성·삭제·이동) 시 해당 키 invalidation.bookmark.gateway.ts: heartbeat 타이머를 Redis 기반으로 교체. 클라이언트 연결/해제 시 Redis에 세션 상태를 기록하고, 주기적인 heartbeat 확인 로직을 게이트웨이에서 처리.4. 단위 테스트 추가 및 업데이트 (test)
redis.service.spec.ts(신규):get/set/del기본 CRUD, TTL 적용 여부,publish/subscribe콜백 호출,onModuleDestroy연결 정리 시나리오 검증.bookmark.service.spec.ts(업데이트): 캐시 hit 경로(DB 미호출), 캐시 miss 경로(DB 조회 후 캐시 저장), 변경 시 캐시 invalidation 흐름 검증. 기존 테스트 중 Redis 없이 작성된 항목 리팩토링.bookmark.gateway.spec.ts(업데이트): Redis heartbeat 연동 경로 검증. 연결/해제 이벤트에서 Redis 호출 분기 및 예외 처리(try-catch) 우회 시나리오 추가.검증 결과
npx tsc --noEmit)jest)