From 13f1c780069cfa549972407e057e951fa78440aa Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Fri, 27 Sep 2024 02:48:27 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20#64=20Reids=20=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config | 2 +- .../com/cabin/plat/config/RedisConfig.java | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/cabin/plat/config/RedisConfig.java diff --git a/config b/config index 5226aa1..0a6c187 160000 --- a/config +++ b/config @@ -1 +1 @@ -Subproject commit 5226aa1f87d0dcbe6b7a4fcb2616bd74761f1be5 +Subproject commit 0a6c1877c41088ce33ce260afa2efa073b42e77f diff --git a/src/main/java/com/cabin/plat/config/RedisConfig.java b/src/main/java/com/cabin/plat/config/RedisConfig.java new file mode 100644 index 0000000..bdb3fc1 --- /dev/null +++ b/src/main/java/com/cabin/plat/config/RedisConfig.java @@ -0,0 +1,48 @@ +package com.cabin.plat.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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.StringRedisSerializer; + +@Configuration +@EnableRedisRepositories // redis 활성화 +public class RedisConfig { + + @Value("${spring.data.redis.host}") + private String redisHost; + + @Value("${spring.data.redis.port}") + private int redisPort; + + @Value("${spring.data.redis.password}") + private String redisPassword; + +// @Value("${spring.data.redis.database}") +// private int database; + + @Bean + public RedisConnectionFactory redisConnectionFactory() { + RedisStandaloneConfiguration redisStandaloneConfiguration = new RedisStandaloneConfiguration(); + redisStandaloneConfiguration.setHostName(redisHost); + redisStandaloneConfiguration.setPort(redisPort); + redisStandaloneConfiguration.setPassword(redisPassword); +// redisStandaloneConfiguration.setDatabase(database); + return new LettuceConnectionFactory(redisStandaloneConfiguration); + } + + @Bean + public RedisTemplate redisTemplate() { + RedisTemplate redisTemplate = new RedisTemplate<>(); + // Redis key, value 직렬화 설정 + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setValueSerializer(new StringRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory()); // ConnectionFactory 설정 + return redisTemplate; + } +} \ No newline at end of file