Merged
Conversation
- Redis Lua 스크립트로 대기열에서 활성 큐로 유저 이동 로직 구현 - 사용자 이동을 처리하는 TRANSFER_USER 명령어 정의 및 설정 - Redis 모듈에서 해당 명령어를 정의하여 사용 가능하도록 설정 - MAX_CAPACITY 기반으로 활성 큐 최대 인원 조절 가능하도록 구현
- `QueueWorker`: 대기 유저를 활성 큐로 이동시키는 구체적인 작업(Task) 로직 구현 - `QueueTrigge`: 워커의 실행 시점 및 스케줄링 주기(Interval) 관리 로직 구현 - 단위 테스트 추가: 스케줄링 주기 준수 여부 및 워커의 작업 수행 결과에 대한 spec.ts 작성
shininghyunho
approved these changes
Jan 15, 2026
Collaborator
shininghyunho
left a comment
There was a problem hiding this comment.
lua 스크립트 처음봤는데 저렇게 생겼군요. 트리거 - 워커 로직 잘봤습니다.
수고하셨습니다.
| }); | ||
| } | ||
|
|
||
| @Cron(CronExpression.EVERY_SECOND) |
Collaborator
There was a problem hiding this comment.
나중에는 환경변수 파일로 뺄수도 있을거같네요!
JichanPark12
approved these changes
Jan 19, 2026
- `QueueTrigger`: 메시지 수신 시 활성 유저 제거 및 오류 로깅 기능 추가 - `QueueWorker`: 활성 큐 처리 스로틀링 로직 및 활성 유저 제거 메서드 구현
- `QueueTrigger`: 크론 표현식을 매 분으로 수정하여 큐 전송 처리 주기 조정
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.
🧭 Summary
Cron(1분) +Pub/Sub(작업 완료 이벤트)로 트리거하여 자동 입장(큐 스케줄링)이 동작하도록 구성했습니다.MAX_CAPACITY)을 기준으로 원자적으로 처리되며, 이동된 유저는 활성 상태(5분)를 redis에 함께 기록합니다.🔗 Linked Issue
🛠 개발 기능(작업 내용)
transferUser) 도입: 대기열 조회, 인원 계산, 이관 작업을 하나의 원자적 단위로 묶었습니다. (동시성 문제 해결, 네트워크 왕복 감소)ZCARD) 기준으로 입장 가능 수(available) 계산ZPOPMIN) 가능한 만큼 pop 후 활성 큐로 이동(ZADD)status:active:{userId}로 TTL 300초(5분) 저장QueueWorker구현: Lua 스크립트를 호출하여 실질적인 유저 이관 작업을 수행하는 Task 로직을 작성했습니다.QueueTrigger구현: 워커의 실행 주기(Interval)를 관리하며, 시스템 설정에 따라 스케줄링을 제어하는 트리거 메커니즘을 구축했습니다.MAX_CAPACITY로 동적으로 활성 큐 사이즈를 조절할 수 있게 하였고, 실행 주기를 포함하여 추후 환경 변수와 연동하거나 redis 자체에 저장하는 방식도 고려중입니다.spec.ts): 모킹을 통해 트리거의 호출 주기와 워커의 커스텀 명령어 실행 여부를 검증하는 테스트 코드를 추가했습니다.🧩 주요 고민과 해결 방법
zcard,zpopmin,zadd로직을 별도의 애플리케이션 단계가 아닌 Redis 내부 Lua 스크립트에서 실행하게 하여 원자성을 확보했습니다.🔍 리뷰 포인트
redis.commands.ts의 Lua 스크립트 로직을 봐주세요 (이해를 돕기 위한 주석을 달았습니다)queue.trigger.ts(언제 실행하는가)와queue.worker.ts(무엇을 실행하는가)를 중점으로 봐주세요.