-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* style: 엔터추가 * feat: DistributedLockAop 빈에서 삭제 * test: 리뷰 좋아요 테스트 주석처리 * feat: redis 설정 파일 주석 처리 * feat: 설정파일에서 redis 연결부분 삭제 * feat: redis 설정 다 삭제
- Loading branch information
1 parent
0ba293c
commit 98a3998
Showing
5 changed files
with
85 additions
and
88 deletions.
There are no files selected for viewing
This file contains 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
136 changes: 68 additions & 68 deletions
136
...ucture/src/main/java/org/depromeet/spot/infrastructure/common/aop/DistributedLockAop.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,69 @@ | ||
package org.depromeet.spot.infrastructure.common.aop; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
|
||
import org.aspectj.lang.ProceedingJoinPoint; | ||
import org.aspectj.lang.annotation.Around; | ||
import org.aspectj.lang.annotation.Aspect; | ||
import org.aspectj.lang.reflect.MethodSignature; | ||
import org.depromeet.spot.common.annotation.DistributedLock; | ||
import org.depromeet.spot.infrastructure.common.util.SpringELParser; | ||
import org.redisson.api.RLock; | ||
import org.redisson.api.RedissonClient; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Aspect | ||
// package org.depromeet.spot.infrastructure.common.aop; | ||
// | ||
// import java.lang.reflect.Method; | ||
// import java.util.Arrays; | ||
// | ||
// import org.aspectj.lang.ProceedingJoinPoint; | ||
// import org.aspectj.lang.annotation.Around; | ||
// import org.aspectj.lang.annotation.Aspect; | ||
// import org.aspectj.lang.reflect.MethodSignature; | ||
// import org.depromeet.spot.common.annotation.DistributedLock; | ||
// import org.depromeet.spot.infrastructure.common.util.SpringELParser; | ||
// import org.redisson.api.RLock; | ||
// import org.redisson.api.RedissonClient; | ||
// | ||
// import lombok.RequiredArgsConstructor; | ||
// import lombok.extern.slf4j.Slf4j; | ||
// | ||
// @Slf4j | ||
// @Aspect | ||
// @Component | ||
@RequiredArgsConstructor | ||
public class DistributedLockAop { | ||
|
||
private final RedissonClient redissonClient; | ||
private final TransactionAop aopForTransaction; | ||
|
||
private static final String REDISSON_LOCK_PREFIX = "LOCK:"; | ||
|
||
@Around("@annotation(org.depromeet.spot.common.annotation.DistributedLock)") | ||
public Object lock(ProceedingJoinPoint joinPoint) throws Throwable { | ||
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
Method method = signature.getMethod(); | ||
DistributedLock distributedLock = method.getAnnotation(DistributedLock.class); | ||
|
||
String lockKey = generateLockKey(signature, joinPoint.getArgs(), distributedLock); | ||
RLock rLock = redissonClient.getLock(lockKey); | ||
|
||
try { | ||
if (!acquireLock(rLock, distributedLock)) { | ||
return false; | ||
} | ||
return aopForTransaction.proceed(joinPoint); | ||
} catch (InterruptedException e) { | ||
log.error(Arrays.toString(e.getStackTrace())); | ||
throw e; | ||
} finally { | ||
releaseLock(rLock); | ||
} | ||
} | ||
|
||
private String generateLockKey( | ||
MethodSignature signature, Object[] args, DistributedLock distributeLock) { | ||
return REDISSON_LOCK_PREFIX | ||
+ SpringELParser.getDynamicValue( | ||
signature.getParameterNames(), args, distributeLock.key()); | ||
} | ||
|
||
private boolean acquireLock(RLock rLock, DistributedLock distributeLock) | ||
throws InterruptedException { | ||
return rLock.tryLock( | ||
distributeLock.waitTime(), distributeLock.leaseTime(), distributeLock.timeUnit()); | ||
} | ||
|
||
private void releaseLock(RLock rLock) { | ||
if (rLock != null && rLock.isHeldByCurrentThread()) { | ||
rLock.unlock(); | ||
} | ||
} | ||
} | ||
// @RequiredArgsConstructor | ||
// public class DistributedLockAop { | ||
// | ||
// private final RedissonClient redissonClient; | ||
// private final TransactionAop aopForTransaction; | ||
// | ||
// private static final String REDISSON_LOCK_PREFIX = "LOCK:"; | ||
// | ||
// @Around("@annotation(org.depromeet.spot.common.annotation.DistributedLock)") | ||
// public Object lock(ProceedingJoinPoint joinPoint) throws Throwable { | ||
// MethodSignature signature = (MethodSignature) joinPoint.getSignature(); | ||
// Method method = signature.getMethod(); | ||
// DistributedLock distributedLock = method.getAnnotation(DistributedLock.class); | ||
// | ||
// String lockKey = generateLockKey(signature, joinPoint.getArgs(), distributedLock); | ||
// RLock rLock = redissonClient.getLock(lockKey); | ||
// | ||
// try { | ||
// if (!acquireLock(rLock, distributedLock)) { | ||
// return false; | ||
// } | ||
// return aopForTransaction.proceed(joinPoint); | ||
// } catch (InterruptedException e) { | ||
// log.error(Arrays.toString(e.getStackTrace())); | ||
// throw e; | ||
// } finally { | ||
// releaseLock(rLock); | ||
// } | ||
// } | ||
// | ||
// private String generateLockKey( | ||
// MethodSignature signature, Object[] args, DistributedLock distributeLock) { | ||
// return REDISSON_LOCK_PREFIX | ||
// + SpringELParser.getDynamicValue( | ||
// signature.getParameterNames(), args, distributeLock.key()); | ||
// } | ||
// | ||
// private boolean acquireLock(RLock rLock, DistributedLock distributeLock) | ||
// throws InterruptedException { | ||
// return rLock.tryLock( | ||
// distributeLock.waitTime(), distributeLock.leaseTime(), distributeLock.timeUnit()); | ||
// } | ||
// | ||
// private void releaseLock(RLock rLock) { | ||
// if (rLock != null && rLock.isHeldByCurrentThread()) { | ||
// rLock.unlock(); | ||
// } | ||
// } | ||
// } |
12 changes: 6 additions & 6 deletions
12
infrastructure/src/main/java/org/depromeet/spot/infrastructure/redis/RedisProperties.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
package org.depromeet.spot.infrastructure.redis; | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "aws.redis") | ||
public record RedisProperties(String host, int port) {} | ||
// package org.depromeet.spot.infrastructure.redis; | ||
// | ||
// import org.springframework.boot.context.properties.ConfigurationProperties; | ||
// | ||
// @ConfigurationProperties(prefix = "aws.redis") | ||
// public record RedisProperties(String host, int port) {} |
This file contains 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
This file contains 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