Skip to content

Commit

Permalink
No jira dev deploy (#207)
Browse files Browse the repository at this point in the history
* style: 엔터추가

* feat: DistributedLockAop 빈에서 삭제

* test: 리뷰 좋아요 테스트 주석처리

* feat: redis 설정 파일 주석 처리

* feat: 설정파일에서 redis 연결부분 삭제

* feat: redis 설정 다 삭제
  • Loading branch information
pminsung12 authored Nov 14, 2024
1 parent 0ba293c commit 98a3998
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 88 deletions.
12 changes: 6 additions & 6 deletions infrastructure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ dependencies {
implementation("org.springframework.cloud:spring-cloud-starter-aws:_")

// redis
implementation("org.springframework.boot:spring-boot-starter-data-redis:_")
implementation("org.redisson:redisson-spring-boot-starter:_")
implementation("it.ozimov:embedded-redis:_") {
exclude(group = "org.slf4j", module = "slf4j-simple")
because("테스트 환경에서 사용할 embedded-redis")
}
// implementation("org.springframework.boot:spring-boot-starter-data-redis:_")
// implementation("org.redisson:redisson-spring-boot-starter:_")
// implementation("it.ozimov:embedded-redis:_") {
// exclude(group = "org.slf4j", module = "slf4j-simple")
// because("테스트 환경에서 사용할 embedded-redis")
// }

// webflux (HTTP 요청에 사용)
implementation("org.springframework.boot:spring-boot-starter-webflux")
Expand Down
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();
// }
// }
// }
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) {}
5 changes: 1 addition & 4 deletions infrastructure/src/main/resources/application-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ aws:
accessKey: ${AWS_ACCESS_KEY}
secretKey: ${AWS_SECRET_KEY}
bucketName: ${S3_BUCKET_NAME}
basicProfileImageUrl: ${S3_BASIC_PROFILE_IMAGE_URL}
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
basicProfileImageUrl: ${S3_BASIC_PROFILE_IMAGE_URL}
8 changes: 4 additions & 4 deletions versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ version.junit=5.9.1

version.org.projectlombok..lombok=1.18.30

version.org.redisson..redisson-spring-boot-starter=3.34.1
#version.org.redisson..redisson-spring-boot-starter=3.34.1

version.org.springframework.boot..spring-boot-starter-test=3.0.1

Expand All @@ -39,9 +39,9 @@ version.com.querydsl..querydsl-jpa=5.0.0

version.org.springframework.cloud..spring-cloud-starter-aws=2.2.6.RELEASE

version.org.springframework.boot..spring-boot-starter-data-redis=3.3.0
#version.org.springframework.boot..spring-boot-starter-data-redis=3.3.0

version.org.redission..redisson-spring-boot-starter=3.26.0
#version.org.redission..redisson-spring-boot-starter=3.26.0

version.org.springframework.boot..spring-boot-configuration-processor=3.0.1

Expand All @@ -61,7 +61,7 @@ version.io.micrometer..micrometer-registry-prometheus=1.12.4

version.com.github.ben-manes.caffeine..caffeine=3.1.8

version.it.ozimov..embedded-redis=0.7.3
#version.it.ozimov..embedded-redis=0.7.3

version.org.testcontainers..testcontainers=1.20.1

Expand Down

0 comments on commit 98a3998

Please sign in to comment.