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