Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
[#26] 레디스 CacheManager 설정
Browse files Browse the repository at this point in the history
- 세션과 캐쉬 레디스 분리
- RedisConfig -> RedisSessionConfig로 naming 변경
  • Loading branch information
choitaehoon committed Nov 16, 2020
1 parent 510df0e commit b7a871b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.social.instagram.config;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
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.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
Expand All @@ -15,12 +18,21 @@
@RequiredArgsConstructor
public class RedisCacheManagerConfig {

private final RedisConnectionFactory redisConnectionFactory;
@Value("${spring.redis.cache.host}")
private String redisHost;

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

@Bean
public RedisConnectionFactory redisCacheConnectionFactory() {
return new LettuceConnectionFactory(new RedisStandaloneConfiguration(redisHost, redisPort));
}

@Bean
public CacheManager redisCacheManager() {
return RedisCacheManager.RedisCacheManagerBuilder
.fromConnectionFactory(redisConnectionFactory)
.fromConnectionFactory(redisCacheConnectionFactory())
.cacheDefaults(redisCacheConfiguration())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
하지만 @Value에서 프로퍼티 파일의 내용을 참조하게 해주면 소스코드의 수정 없이 @Value를 통해 프로퍼티에 주입되는 값을 변경할 수 있다.
*/
@Configuration
public class RedisConfig {
public class RedisSessionConfig {

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

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

/*
Expand Down
8 changes: 6 additions & 2 deletions src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ spring:
format_sql: true

redis:
host: 127.0.0.1
port: 6379
session:
host: 127.0.0.1
port: 6379
cache:
host: 127.0.0.1
port: 6378

#hibernate가 ?에 어떤값이 들어가 있는지 구체적으로 알려주는 설정
logging:
Expand Down

0 comments on commit b7a871b

Please sign in to comment.