2020public class GameRepository {
2121
2222 private final RedisTemplate <String , String > redisTemplate ;
23+ //todo: Lock 관련 코드 전면 수정
2324 private final RedissonClient redissonClient ;
2425
2526 public GameRepository (@ Qualifier ("socketStringRedisTemplate" ) RedisTemplate <String , String > redisTemplate , RedissonClient redissonClient ) {
@@ -39,11 +40,11 @@ public static String getGameKey(String roomId) {
3940 */
4041 public void saveGameMeta (GameMeta gameMeta ) {
4142 String redisKey = getGameKey (gameMeta .getRoomId ()); // Redis 해시 키
42- String lockKey = "lock:" + redisKey ; // 락 키
43-
44- RLock lock = redissonClient .getLock (lockKey );
45- try {
46- if (lock .tryLock (1 , 5 , TimeUnit .SECONDS )) { // 1초 기다리고, 5초 동안 유지
43+ // String lockKey = "lock:" + redisKey; // 락 키
44+ //
45+ // RLock lock = redissonClient.getLock(lockKey);
46+ // try {
47+ // if (lock.tryLock(1, 5, TimeUnit.SECONDS)) { // 1초 기다리고, 5초 동안 유지
4748 Map <String , Object > gameData = Map .of (
4849 "gameType" , gameMeta .getGameType ().name (),
4950 "difficulty" , gameMeta .getDifficulty ().name (),
@@ -55,40 +56,40 @@ public void saveGameMeta(GameMeta gameMeta) {
5556 "playerWon" , String .valueOf (gameMeta .getPlayerWon ())
5657 );
5758 redisTemplate .opsForHash ().putAll (getGameKey (gameMeta .getRoomId ()), gameData );
58- } else {
59- throw new SocketCustomException (ErrorType .GAME , GameExceptionCode .LOCK_ACQUISITION_FAILED );
60- }
61- } catch (InterruptedException e ) {
62- Thread .currentThread ().interrupt (); //
63- throw new SocketCustomException (ErrorType .GAME , GameExceptionCode .LOCK_INTERRUPTED );
64- } finally {
65- if (lock .isHeldByCurrentThread ()) {
66- lock .unlock ();
67- }
68- }
59+ // } else {
60+ // throw new SocketCustomException(ErrorType.GAME, GameExceptionCode.LOCK_ACQUISITION_FAILED);
61+ // }
62+ // } catch (InterruptedException e) {
63+ // Thread.currentThread().interrupt(); //
64+ // throw new SocketCustomException(ErrorType.GAME, GameExceptionCode.LOCK_INTERRUPTED);
65+ // } finally {
66+ // if (lock.isHeldByCurrentThread()) {
67+ // lock.unlock();
68+ // }
69+ // }
6970 }
7071
7172 /**
7273 * Game 메타데이터만 조회
7374 */
7475 public Map <Object , Object > findGameMeta (String roomId ) {
7576 String redisKey = getGameKey (roomId );
76- String lockKey = "lock:" + redisKey ;
77- RLock lock = redissonClient .getLock (lockKey );
78- try {
79- if (lock .tryLock (1 , 5 , TimeUnit .SECONDS )) { // 1초 기다리고, 5초 동안 유지
77+ // String lockKey = "lock:" + redisKey;
78+ // RLock lock = redissonClient.getLock(lockKey);
79+ // try {
80+ // if (lock.tryLock(1, 5, TimeUnit.SECONDS)) { // 1초 기다리고, 5초 동안 유지
8081 return redisTemplate .opsForHash ().entries (redisKey );
81- } else {
82- throw new SocketCustomException (ErrorType .GAME , GameExceptionCode .LOCK_ACQUISITION_FAILED );
83- }
84- } catch (InterruptedException e ) {
85- Thread .currentThread ().interrupt (); //
86- throw new SocketCustomException (ErrorType .GAME , GameExceptionCode .LOCK_INTERRUPTED );
87- } finally {
88- if (lock .isHeldByCurrentThread ()) {
89- lock .unlock ();
90- }
91- }
82+ // } else {
83+ // throw new SocketCustomException(ErrorType.GAME, GameExceptionCode.LOCK_ACQUISITION_FAILED);
84+ // }
85+ // } catch (InterruptedException e) {
86+ // Thread.currentThread().interrupt(); //
87+ // throw new SocketCustomException(ErrorType.GAME, GameExceptionCode.LOCK_INTERRUPTED);
88+ // } finally {
89+ // if (lock.isHeldByCurrentThread()) {
90+ // lock.unlock();
91+ // }
92+ // }
9293 }
9394
9495 public void deleteGameMeta (String roomId ){
0 commit comments