Skip to content

Commit

Permalink
✏️ [FIX] Redis 분산락 코드 일부 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
aj4941 committed Nov 25, 2024
1 parent 2f7b48b commit dae1a98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
14 changes: 5 additions & 9 deletions src/main/java/swm_nm/morandi/aop/lock/MemberLockAspect.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import swm_nm.morandi.global.utils.SecurityUtils;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;

@Aspect
@Component
Expand All @@ -23,8 +24,6 @@
public class MemberLockAspect {

private final RedissonClient redissonClient;

private final StringRedisTemplate redisTemplate;
private final String MEMBER_LOCK_KEY = "memberLock";
@Pointcut("@annotation(swm_nm.morandi.aop.annotation.MemberLock)")
public void memberLockPointcut() {
Expand All @@ -42,15 +41,12 @@ public Object MEMBERLock(ProceedingJoinPoint joinPoint) throws Throwable {
throw new MorandiException(LockErrorCode.MEMBER_LOCKED);
}
return joinPoint.proceed();
} catch (InterruptedException e) {
throw new MorandiException(LockErrorCode.INTERRUPT_ERROR);
} finally {
if (locked) {
unlock(memberLockKey);
lock.unlock();
}
}
}
private void unlock(String key) {
redisTemplate.delete(key);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
@RequiredArgsConstructor
@Getter
public enum LockErrorCode implements ErrorCode {
MEMBER_LOCKED(HttpStatus.CONFLICT, "한 번에 여러 번의 요청을 받을 수 없습니다. 잠시만 기다려주세요.");
MEMBER_LOCKED(HttpStatus.CONFLICT, "한 번에 여러 번의 요청을 받을 수 없습니다. 잠시만 기다려주세요."),
INTERRUPT_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "인터럽트 예외가 발생했습니다.");

private final HttpStatus httpStatus;
private final String message;


}

0 comments on commit dae1a98

Please sign in to comment.