Skip to content

Commit

Permalink
feat: redis 관련 설정 정의(#28)
Browse files Browse the repository at this point in the history
- redis 커넥션 팩토리 빈 등록
- CRUD 연산 지원을 위한 RedisTemplate 빈 등록
  • Loading branch information
Minjae-An committed Mar 16, 2024
1 parent ccd2145 commit d06aebc
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions be/src/main/java/yeonba/be/config/RedisConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package yeonba.be.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.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

@Configuration
public class RedisConfig {

@Value("${spring.data.redis.host}")
private String host;

@Value("${spring.data.redis.port}")
private int port;

@Bean
public RedisConnectionFactory redisConnectionFactory() {

return new LettuceConnectionFactory(host, port);
}

@Bean
public RedisTemplate<String, Object> redisTemplate() {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(redisConnectionFactory());

redisTemplate.setDefaultSerializer(new StringRedisSerializer());

return redisTemplate;
}
}

0 comments on commit d06aebc

Please sign in to comment.