Skip to content

Conversation

@j-zzi
Copy link
Contributor

@j-zzi j-zzi commented Aug 12, 2025

PR 의 종류는 어떤 것인가요?

  • 새로운 기능

수정이 필요하게된 이유가 무엇인가요? (Jira 이슈가 있다면크를 연결해주세요)

  • Redis의 원자적 처리를 위한 multi() 기능 추가가 필요했습니다
  • 여러 Redis 명령을 하나의 트랜잭션으로 실행하여 데이터 일관성을 보장하고 성능을 향상시키기 위함입니다

무엇을 어떻게 변경했나요?

1. MultiOperations 인터페이스 추가

  • Redis의 모든 주요 자료구조(String, List, Hash, Set)에 대한 multi 명령 인터페이스 정의
  • 체이닝 방식으로 여러 명령을 연결할 수 있는 구조

2. FastCache 클래스에 multi() 메서드 구현

public multi(): MultiOperations {
  // Redis multi 클라이언트 생성
  // 각 명령을 operations 배열에 저장
  // exec() 시 모든 명령을 원자적으로 실행
}

3. 지원하는 명령들

  • 기본 키-값: set, get, remove
  • 리스트: listPush, listPop, listUnshift, listShift
  • 해시맵: mapSet, mapGet, mapRemove, mapSetAll, mapGetAll, mapRemoveAll
  • : setAdd, setRemove, setContains, setLength
  • 만료 시간: expire

4. ioredis 호환성 수정

  • multiClient.exec() 결과가 [error, value] 형태로 반환되는 것을 실제 값만 추출하도록 수정
  • result.map(([, value]) => value)로 에러 부분 제거

코드 변경을 이해하기 위한 배경지식이 필요하다면 설명 해주세요.

Redis MULTI/EXEC 패턴

  • MULTI: 트랜잭션 시작
  • 명령들: 여러 Redis 명령을 큐에 추가
  • EXEC: 모든 명령을 원자적으로 실행

원자적 실행의 장점

  • 데이터 일관성: 모든 명령이 성공하거나 모두 실패
  • 성능 향상: 네트워크 왕복 횟수 감소
  • 동시성 제어: 다른 클라이언트의 간섭 방지

ioredis 라이브러리 특성

  • multi().exec() 결과가 [error, value] 형태로 반환
  • 실제 Redis 표준과 다르므로 결과값만 추출하는 로직 필요

디펜던시 변경이 있나요?

  • 없음 (기존 ioredis 의존성만 사용)

어떻게 테스트 하셨나요?

1. 단위 테스트 추가

  • src/FastCache.spec.tsmulti() 기능에 대한 포괄적인 테스트 추가
  • 각 자료구조별 명령 테스트
  • 복합 명령 실행 테스트
  • 에러 처리 테스트

2. 테스트 케이스

// 기본 키-값 조작
test('set과 get을 함께 실행할 수 있다')

// 리스트 조작
test('리스트 관련 명령을 실행할 수 있다')

// 해시맵 조작
test('해시맵 관련 명령을 실행할 수 있다')

// 셋 조작
test('셋 관련 명령을 실행할 수 있다')

// 복합 명령
test('여러 타입의 명령을 함께 실행할 수 있다')

3. 실제 Redis 동작 검증

  • 각 명령의 반환값이 Redis 표준과 일치하는지 확인
  • 실제 데이터 저장/조회가 올바르게 되는지 검증

코드의 실행결과를 볼 수 있는 로그나 이미지가 있다면 첨부해주세요.

사용 예시

const cache = FastCache.create();

// 사용자 정보를 원자적으로 설정
const results = await cache.multi()
  .set('user:123', 'John Doe', 3600)
  .mapSet('user:123:profile', 'name', 'John Doe')
  .mapSet('user:123:profile', 'email', 'john@example.com')
  .setAdd('user:123:tags', 'premium', 'verified')
  .listPush('user:123:activities', 'login:2024-01-01')
  .expire('user:123:profile', 7200)
  .exec();

console.log('Multi execution results:', results);
// ['OK', 1, 1, 2, 1, 1]

테스트 결과

  • 모든 테스트 케이스 통과
  • Redis 표준과 일치하는 반환값 확인
  • 원자적 실행 검증 완료

@j-zzi j-zzi self-assigned this Aug 12, 2025
@day1-dev-adm day1-dev-adm added the enhancement New feature or request label Aug 12, 2025
@j-zzi j-zzi marked this pull request as ready for review August 12, 2025 04:41
@j-zzi j-zzi force-pushed the feat/redis-multi branch 4 times, most recently from e86b3ac to 7ba39c7 Compare August 12, 2025 05:24
@j-zzi j-zzi requested a review from soomtong August 12, 2025 05:25
@j-zzi j-zzi force-pushed the feat/redis-multi branch from 7ba39c7 to a13874c Compare August 12, 2025 05:51
@j-zzi j-zzi force-pushed the feat/redis-multi branch from a13874c to ea1de02 Compare August 12, 2025 05:52
Copy link
Contributor

@soomtong soomtong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@kooks7 kooks7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@j-zzi j-zzi merged commit 8e3a60b into main Aug 19, 2025
1 check passed
@j-zzi j-zzi deleted the feat/redis-multi branch August 19, 2025 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants