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; + } +}