From 0e9e5f2bd0ca8f6a4fddc61b3dcd67f8ddd8f2f0 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sun, 11 Aug 2024 10:59:46 +0900 Subject: [PATCH 1/5] =?UTF-8?q?conf:=20=ED=99=98=EA=B2=BD=EB=B3=84=20?= =?UTF-8?q?=EC=84=A4=EC=A0=95=20=ED=8C=8C=EC=9D=BC=EC=97=90=20=EB=8C=80?= =?UTF-8?q?=ED=95=9C=20gitignore=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b335a8f..a74400f 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,6 @@ out/ ### application.yml ### application.yml +application-local.yml +application-dev.yml +application-prod.yml \ No newline at end of file From cff5feae7c52faa66d28d9e51f699d13e077e7b5 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sun, 11 Aug 2024 11:05:40 +0900 Subject: [PATCH 2/5] =?UTF-8?q?fix:=20ci.yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 889ff99..de9fbee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,11 +28,14 @@ jobs: - name: Make test properties env: - PROPERTIES: ${{ secrets.PROPERTIES_TEST }} + PROPERTIES: ${{ secrets.PROPERTIES }} + PROPERTIES_TEST: ${{ secrets.PROPERTIES_TEST }} run: | mkdir -p ./src/test/resources && cd "$_" touch ./application.yml + touch ./application-test.yml echo $PROPERTIES | base64 --decode > application.yml + echo $PROPERTIES_TEST | base64 --decode > application-test.yml shell: bash - name: Setup Gradle From 59e18777db3880200eccb23ed0a7ebc3fe71c5c9 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sun, 11 Aug 2024 11:05:49 +0900 Subject: [PATCH 3/5] =?UTF-8?q?fix:=20dev=5Fcd.yml=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/dev_cd.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev_cd.yml b/.github/workflows/dev_cd.yml index 7b60b99..079014d 100644 --- a/.github/workflows/dev_cd.yml +++ b/.github/workflows/dev_cd.yml @@ -55,11 +55,14 @@ jobs: - name: Make test properties env: - PROPERTIES: ${{ secrets.PROPERTIES_TEST }} + PROPERTIES: ${{ secrets.PROPERTIES }} + PROPERTIES_TEST: ${{ secrets.PROPERTIES_TEST }} run: | mkdir -p ./src/test/resources && cd "$_" touch ./application.yml + touch ./application-test.yml echo $PROPERTIES | base64 --decode > application.yml + echo $PROPERTIES_TEST | base64 --decode > application-test.yml shell: bash - name: Setup Gradle From 81e276541887e8c8cc929e758fcc31860f95cf71 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sun, 11 Aug 2024 11:06:17 +0900 Subject: [PATCH 4/5] =?UTF-8?q?feat:=20=EB=8B=A8=EC=9D=BC=20=EB=A0=88?= =?UTF-8?q?=EB=94=94=EC=8A=A4=20=EC=9D=B8=EC=8A=A4=ED=84=B4=EC=8A=A4?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=B4=EC=84=9C=20profile=20=EC=96=B4?= =?UTF-8?q?=EB=85=B8=ED=85=8C=EC=9D=B4=EC=85=98=EC=9D=84=20=ED=86=B5?= =?UTF-8?q?=ED=95=9C=20=ED=99=98=EA=B2=BD=EB=B3=84=20=EC=84=A4=EC=A0=95=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../elswhereuserservice/global/config/redis/RedisConfig.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisConfig.java b/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisConfig.java index d151bf4..3f2c15c 100644 --- a/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisConfig.java +++ b/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisConfig.java @@ -1,8 +1,10 @@ package com.wl2c.elswhereuserservice.global.config.redis; import org.springframework.beans.factory.annotation.Value; +import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; import org.springframework.data.redis.connection.RedisPassword; import org.springframework.data.redis.connection.RedisStandaloneConfiguration; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; @@ -10,6 +12,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; @Configuration +@EnableCaching +@Profile({"local", "test", "dev"}) public class RedisConfig { @Value("${spring.data.redis.host}") From 7ca2a87c4790102d3b2df8e66a03d7fff1545205 Mon Sep 17 00:00:00 2001 From: kjungw1025 Date: Sun, 11 Aug 2024 11:06:45 +0900 Subject: [PATCH 5/5] =?UTF-8?q?feat:=20=EB=A0=88=EB=94=94=EC=8A=A4=20?= =?UTF-8?q?=ED=81=B4=EB=9F=AC=EC=8A=A4=ED=84=B0=20=EB=AA=A8=EB=93=9C?= =?UTF-8?q?=EC=97=90=20=EB=8C=80=ED=95=9C=20=ED=99=98=EA=B2=BD=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20=EC=BD=94=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/redis/RedisClusterConfig.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisClusterConfig.java diff --git a/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisClusterConfig.java b/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisClusterConfig.java new file mode 100644 index 0000000..a4063aa --- /dev/null +++ b/src/main/java/com/wl2c/elswhereuserservice/global/config/redis/RedisClusterConfig.java @@ -0,0 +1,82 @@ +package com.wl2c.elswhereuserservice.global.config.redis; + +import io.lettuce.core.ClientOptions; +import io.lettuce.core.SocketOptions; +import io.lettuce.core.cluster.ClusterClientOptions; +import io.lettuce.core.cluster.ClusterTopologyRefreshOptions; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.data.redis.connection.RedisClusterConfiguration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.connection.RedisNode; +import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration; +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +import java.time.Duration; +import java.util.List; + +@Configuration +@EnableCaching +@Profile({"prod"}) +public class RedisClusterConfig { + + @Value("${spring.data.redis.cluster.nodes}") + private List clusterNodes; + + @Value("${spring.data.redis.password}") + private String password; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + List redisNodes = clusterNodes.stream() + .map(clusterNode -> new RedisNode(clusterNode.split(":")[0], Integer.parseInt(clusterNode.split(":")[1]))) + .toList(); + RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(); + clusterConfiguration.setClusterNodes(redisNodes); + clusterConfiguration.setPassword(password); + + // Socket 옵션 + SocketOptions socketOptions = SocketOptions.builder() + .connectTimeout(Duration.ofMillis(100L)) + .keepAlive(true) + .build(); + + // Cluster topology refresh 옵션 + ClusterTopologyRefreshOptions clusterTopologyRefreshOptions = ClusterTopologyRefreshOptions.builder() + .dynamicRefreshSources(true) + .enableAllAdaptiveRefreshTriggers() + .enablePeriodicRefresh(Duration.ofMinutes(30L)) + .build(); + + // Cluster Client 옵션 + ClientOptions clientOptions = ClusterClientOptions.builder() + .topologyRefreshOptions(clusterTopologyRefreshOptions) + .socketOptions(socketOptions) + .build(); + + // Lettuce Client 옵션 + LettuceClientConfiguration clientConfiguration = LettuceClientConfiguration.builder() + .clientOptions(clientOptions) + .commandTimeout(Duration.ofMillis(3000L)) + .build(); + + return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration); + } + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashValueSerializer(new StringRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory()); + return redisTemplate; + } + +}