From 6069271c9bc70ed03dc142b28acd77ddd475e2da Mon Sep 17 00:00:00 2001 From: BYEONGRYEOL Date: Sun, 18 Aug 2024 00:56:59 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20#125=20deploy=20/=20staging,local=20?= =?UTF-8?q?=ED=99=98=EA=B2=BD=20Config=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...fig.java => RedisConfigDeployProfile.java} | 21 +++------ .../RedisConfigStagingAndLocalProfile.java | 43 +++++++++++++++++++ 2 files changed, 50 insertions(+), 14 deletions(-) rename genti-auth/src/main/java/com/gt/genti/config/{RedisConfig.java => RedisConfigDeployProfile.java} (85%) create mode 100644 genti-auth/src/main/java/com/gt/genti/config/RedisConfigStagingAndLocalProfile.java diff --git a/genti-auth/src/main/java/com/gt/genti/config/RedisConfig.java b/genti-auth/src/main/java/com/gt/genti/config/RedisConfigDeployProfile.java similarity index 85% rename from genti-auth/src/main/java/com/gt/genti/config/RedisConfig.java rename to genti-auth/src/main/java/com/gt/genti/config/RedisConfigDeployProfile.java index 85a0232e..dd4943a6 100644 --- a/genti-auth/src/main/java/com/gt/genti/config/RedisConfig.java +++ b/genti-auth/src/main/java/com/gt/genti/config/RedisConfigDeployProfile.java @@ -4,6 +4,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; @@ -12,21 +13,17 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; -import lombok.RequiredArgsConstructor; - +@Profile("deploy") @Configuration @EnableRedisRepositories -@RequiredArgsConstructor -public class RedisConfig { +public class RedisConfigDeployProfile { @Value("${redis.host}") - private String host; - + String host; @Value("${redis.port}") - private int port; - + int port; @Value("${redis.password}") - private String password; + String password; @Bean public RedisConnectionFactory redisConnectionFactory() { @@ -41,13 +38,9 @@ public RedisConnectionFactory redisConnectionFactory() { @Primary public RedisTemplate redisTemplate() { RedisTemplate redisTemplate = new RedisTemplate<>(); - // ObjectMapper objectMapper = new ObjectMapper(); - // objectMapper.registerModule(new JavaTimeModule()); - redisTemplate.setKeySerializer(new StringRedisSerializer()); redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); redisTemplate.setConnectionFactory(redisConnectionFactory()); return redisTemplate; } - -} \ No newline at end of file +} diff --git a/genti-auth/src/main/java/com/gt/genti/config/RedisConfigStagingAndLocalProfile.java b/genti-auth/src/main/java/com/gt/genti/config/RedisConfigStagingAndLocalProfile.java new file mode 100644 index 00000000..0095b0a0 --- /dev/null +++ b/genti-auth/src/main/java/com/gt/genti/config/RedisConfigStagingAndLocalProfile.java @@ -0,0 +1,43 @@ +package com.gt.genti.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +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.repository.configuration.EnableRedisRepositories; +import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Profile({"staging", "local"}) +@Configuration +@EnableRedisRepositories +public class RedisConfigStagingAndLocalProfile { + + @Value("${redis.host}") + String host; + @Value("${redis.port}") + int port; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration redisConfiguration = new RedisStandaloneConfiguration(); + redisConfiguration.setHostName(host); + redisConfiguration.setPort(port); + return new LettuceConnectionFactory(redisConfiguration); + } + + @Bean + @Primary + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + return redisTemplate; + } +}