Skip to content

Commit

Permalink
Merge pull request #127 from Genti2024/feat/redis-profile
Browse files Browse the repository at this point in the history
Feat: #125 redis 환경별 config 분리
  • Loading branch information
LeeJae-H authored Aug 17, 2024
2 parents a970360 + 6069271 commit acc9b66
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -41,13 +38,9 @@ public RedisConnectionFactory redisConnectionFactory() {
@Primary
public RedisTemplate<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
// ObjectMapper objectMapper = new ObjectMapper();
// objectMapper.registerModule(new JavaTimeModule());

redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory());
return redisTemplate;
}

}
}
Original file line number Diff line number Diff line change
@@ -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<String, String> redisTemplate() {
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
redisTemplate.setConnectionFactory(redisConnectionFactory());
return redisTemplate;
}
}

0 comments on commit acc9b66

Please sign in to comment.