Skip to content

Commit daf9dbe

Browse files
committed
update: ElastiCache에서 서버에 직접 redis 클러스터 구성으로 변경 (sharetreats-team#43)
1 parent 4264763 commit daf9dbe

File tree

3 files changed

+20
-34
lines changed

3 files changed

+20
-34
lines changed

.github/workflows/deploy.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ jobs:
3333
spring.datasource.url: ${{ secrets.RDS_URL }}
3434
spring.datasource.username: ${{ secrets.RDS_USERNAME }}
3535
spring.datasource.password: ${{ secrets.RDS_PASSWORD }}
36-
spring.redis.gift-history.host: ${{ secrets.ELASTICACHE_ENDPOINT }}
37-
spring.redis.token.host: ${{ secrets.ELASTICACHE_TOKEN_ENDPOINT }}
3836
cloud.aws.s3.credentials.accesskey: ${{ secrets.AWS_S3_ACCESS_KEY_ID }}
3937
cloud.aws.s3.credentials.secretkey: ${{ secrets.AWS_S3_SECRET_ACCESS_KEY }}
4038
viber.auth.token: ${{ secrets.VIBER_AUTH_TOKEN }}
Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.sharetreats.chatbot.infra.config;
22

3+
import io.lettuce.core.ReadFrom;
34
import org.springframework.beans.factory.annotation.Value;
45
import org.springframework.context.annotation.Bean;
56
import org.springframework.context.annotation.Configuration;
67
import org.springframework.context.annotation.Primary;
78
import org.springframework.data.redis.connection.RedisClusterConfiguration;
9+
import org.springframework.data.redis.connection.RedisConnectionFactory;
810
import org.springframework.data.redis.connection.RedisNode;
11+
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
912
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
1013
import org.springframework.data.redis.core.RedisTemplate;
1114
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
@@ -14,36 +17,28 @@
1417
@Configuration
1518
public class RedisConfig {
1619

17-
@Value("${spring.redis.gift-history.host}")
18-
private String redisHost;
19-
20-
@Value("${spring.redis.gift-history.port}")
21-
private int redisPort;
22-
23-
@Value("${spring.redis.token.host}")
24-
private String tokenRedisHost;
25-
26-
@Value("${spring.redis.token.port}")
27-
private int tokenRedisPort;
28-
2920
@Bean
30-
@Primary
31-
public LettuceConnectionFactory connectionFactory() {
32-
return new LettuceConnectionFactory(redisHost, redisPort);
33-
}
34-
35-
@Bean
36-
public LettuceConnectionFactory tokenConnectionFactory() {
37-
RedisClusterConfiguration clusterConfig = new RedisClusterConfiguration();
38-
clusterConfig.addClusterNode(new RedisNode(tokenRedisHost, tokenRedisPort));
39-
40-
return new LettuceConnectionFactory(clusterConfig);
21+
public RedisConnectionFactory redisConnectionFactory() {
22+
LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder()
23+
.readFrom(ReadFrom.REPLICA_PREFERRED)
24+
.build();
25+
26+
RedisClusterConfiguration redisClusterConfiguration = new RedisClusterConfiguration()
27+
.clusterNode("localhost", 8000)
28+
.clusterNode("localhost", 8001)
29+
.clusterNode("localhost", 8002)
30+
.clusterNode("localhost", 8003)
31+
.clusterNode("localhost", 8004)
32+
.clusterNode("localhost", 8005);
33+
34+
LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisClusterConfiguration, clientConfiguration);
35+
return lettuceConnectionFactory;
4136
}
4237
@Bean
4338
public RedisTemplate<String, Object> redisTemplate() {
4439
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
4540
redisTemplate.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
46-
redisTemplate.setConnectionFactory(connectionFactory());
41+
redisTemplate.setConnectionFactory(redisConnectionFactory());
4742
return redisTemplate;
4843
}
4944

@@ -52,7 +47,7 @@ public RedisTemplate<String, Object> redisTemplate() {
5247
public RedisTemplate<String, String> tokenRedisTemplate() {
5348
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
5449
redisTemplate.setDefaultSerializer(new StringRedisSerializer());
55-
redisTemplate.setConnectionFactory(tokenConnectionFactory());
50+
redisTemplate.setConnectionFactory(redisConnectionFactory());
5651
return redisTemplate;
5752
}
5853
}

src/main/resources/application.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ spring:
1919
jpa:
2020
hibernate:
2121
ddl-auto: update
22-
redis:
23-
gift-history:
24-
host: ${ELASTICACHE_ENDPOINT}
25-
port: 6379
26-
token:
27-
host: ${ELASTICACHE_TOKEN_ENDPOINT}
28-
port: 6380
2922

3023
mail:
3124
host: smtp.gmail.com

0 commit comments

Comments
 (0)