From 1799fc48c9aa06d58be30b8479bd3e48b86c6858 Mon Sep 17 00:00:00 2001 From: Son Gahyun <77109954+hyun2371@users.noreply.github.com> Date: Fri, 3 May 2024 20:08:52 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20:=20redis=20=EB=B9=84=EB=B0=80?= =?UTF-8?q?=EB=B2=88=ED=98=B8=20=ED=95=A0=EB=8B=B9,=20=EA=B2=BD=EB=A7=A4?= =?UTF-8?q?=20=EC=83=81=ED=83=9C=20=EC=8A=A4=EC=BC=80=EC=A4=84=EB=9F=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20(#164)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [feat] : Lettuce 연결 위한 redis 비밀번호 설정 추가 * [feat] : Redisson 연결 위한 redis 비밀번호 설정 추가 * [feat] : 경매 상태 관련 스케줄러 함수 수정 --- .../java/dev/handsup/common/config/RedisConfig.java | 12 +++++++++++- .../auction/AuctionQueryRepositoryImpl.java | 4 ++-- .../dev/handsup/common/config/RedissonConfig.java | 13 +++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/dev/handsup/common/config/RedisConfig.java b/api/src/main/java/dev/handsup/common/config/RedisConfig.java index f29d5892..974e8a2f 100644 --- a/api/src/main/java/dev/handsup/common/config/RedisConfig.java +++ b/api/src/main/java/dev/handsup/common/config/RedisConfig.java @@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; @@ -26,9 +27,18 @@ public class RedisConfig { @Value("${spring.data.redis.port}") private int port; + @Value("${spring.data.redis.password:}")// + private String password; + @Bean public RedisConnectionFactory redisConnectionFactory() { - return new LettuceConnectionFactory(host, port); + RedisStandaloneConfiguration config = new RedisStandaloneConfiguration(); + config.setHostName(host); + config.setPort(port); + if (!password.isEmpty()) { + config.setPassword(password); + } + return new LettuceConnectionFactory(config); } @Bean diff --git a/core/src/main/java/dev/handsup/auction/repository/auction/AuctionQueryRepositoryImpl.java b/core/src/main/java/dev/handsup/auction/repository/auction/AuctionQueryRepositoryImpl.java index 8801d139..60007384 100644 --- a/core/src/main/java/dev/handsup/auction/repository/auction/AuctionQueryRepositoryImpl.java +++ b/core/src/main/java/dev/handsup/auction/repository/auction/AuctionQueryRepositoryImpl.java @@ -102,14 +102,14 @@ public void updateAuctionStatusAfterEndDate() { queryFactory .update(auction) .set(auction.status, AuctionStatus.CANCELED) - .where(auction.endDate.eq(LocalDate.now().minusDays(1)), + .where(auction.endDate.lt(LocalDate.now()), auction.biddingCount.eq(0)) .execute(); queryFactory .update(auction) .set(auction.status, AuctionStatus.TRADING) - .where(auction.endDate.eq(LocalDate.now().minusDays(1)), + .where(auction.endDate.lt(LocalDate.now()), auction.biddingCount.goe(1)) .execute(); } diff --git a/core/src/main/java/dev/handsup/common/config/RedissonConfig.java b/core/src/main/java/dev/handsup/common/config/RedissonConfig.java index f6ae458e..8a76ee8b 100644 --- a/core/src/main/java/dev/handsup/common/config/RedissonConfig.java +++ b/core/src/main/java/dev/handsup/common/config/RedissonConfig.java @@ -15,12 +15,17 @@ public class RedissonConfig { @Value("${spring.data.redis.port}") private int port; + @Value("${spring.data.redis.password:}") + private String password; + @Bean public RedissonClient redissonClient() { - RedissonClient redisson = null; Config config = new Config(); - config.useSingleServer().setAddress(REDISSON_HOST_PREFIX + host + ":" + port); - redisson = Redisson.create(config); - return redisson; + config.useSingleServer() + .setAddress(REDISSON_HOST_PREFIX + host + ":" + port); + if (!password.isEmpty()) { + config.useSingleServer().setPassword(password); + } + return Redisson.create(config); } }