Skip to content

Commit

Permalink
fix: [BE] 방삭제시 player 정보도 함께 삭제
Browse files Browse the repository at this point in the history
  • Loading branch information
DongHoonYu96 committed Dec 2, 2024
1 parent e324d41 commit 3c1e403
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion BE/src/game/redis/game-redis-memory.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class GameRedisMemoryService {
* 비활성 방을 체크하고 정리하는 크론 작업
* SCAN을 사용하여 대규모 방 목록도 안전하게 처리
*/
@Cron(CronExpression.EVERY_SECOND)
@Cron(CronExpression.EVERY_10_MINUTES)
async checkInactiveRooms(): Promise<void> {
this.logger.verbose('비활성 방 체크 시작');
try {
Expand Down
9 changes: 9 additions & 0 deletions BE/src/game/redis/subscribers/room.cleanup.subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export class RoomCleanupSubscriber extends RedisSubscriber {
try {
const pipeline = this.redis.pipeline();

// 1. 방에 속한 플레이어 목록 가져오기, 200명미만 -> smembers 사용!
const players = await this.redis.smembers(REDIS_KEY.ROOM_PLAYERS(roomId));

// 2. 플레이어 데이터 삭제
for (const playerId of players) {
pipeline.del(REDIS_KEY.PLAYER(playerId)); // 플레이어 기본 데이터
pipeline.del(`${REDIS_KEY.PLAYER(playerId)}:Changes`); // 플레이어 Changes 데이터
}

// 1. 방 관련 기본 데이터 삭제
pipeline.del(REDIS_KEY.ROOM(roomId));
pipeline.del(REDIS_KEY.ROOM_PLAYERS(roomId));
Expand Down

0 comments on commit 3c1e403

Please sign in to comment.