From 3c1e403630121e0e41b2f8917ef16ebdac2e70d3 Mon Sep 17 00:00:00 2001 From: DongHoonYu96 Date: Mon, 2 Dec 2024 18:39:13 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20[BE]=20=EB=B0=A9=EC=82=AD=EC=A0=9C?= =?UTF-8?q?=EC=8B=9C=20player=20=EC=A0=95=EB=B3=B4=EB=8F=84=20=ED=95=A8?= =?UTF-8?q?=EA=BB=98=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BE/src/game/redis/game-redis-memory.service.ts | 2 +- BE/src/game/redis/subscribers/room.cleanup.subscriber.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/BE/src/game/redis/game-redis-memory.service.ts b/BE/src/game/redis/game-redis-memory.service.ts index adc8c826..12bfc8b1 100644 --- a/BE/src/game/redis/game-redis-memory.service.ts +++ b/BE/src/game/redis/game-redis-memory.service.ts @@ -26,7 +26,7 @@ export class GameRedisMemoryService { * 비활성 방을 체크하고 정리하는 크론 작업 * SCAN을 사용하여 대규모 방 목록도 안전하게 처리 */ - @Cron(CronExpression.EVERY_SECOND) + @Cron(CronExpression.EVERY_10_MINUTES) async checkInactiveRooms(): Promise { this.logger.verbose('비활성 방 체크 시작'); try { diff --git a/BE/src/game/redis/subscribers/room.cleanup.subscriber.ts b/BE/src/game/redis/subscribers/room.cleanup.subscriber.ts index be905cf5..5409e852 100644 --- a/BE/src/game/redis/subscribers/room.cleanup.subscriber.ts +++ b/BE/src/game/redis/subscribers/room.cleanup.subscriber.ts @@ -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));