Skip to content

Commit 2bb9afd

Browse files
committedApr 25, 2024
build:Redis 의존성 추가 및 설정 추가
1 parent 77681fe commit 2bb9afd

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
 

‎build.gradle

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ repositories {
2222
}
2323

2424
dependencies {
25-
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
2625
implementation 'org.springframework.boot:spring-boot-starter-web'
2726
compileOnly 'org.projectlombok:lombok'
2827
developmentOnly 'org.springframework.boot:spring-boot-devtools'
29-
runtimeOnly 'com.h2database:h2'
3028
annotationProcessor 'org.projectlombok:lombok'
3129
testImplementation 'org.springframework.boot:spring-boot-starter-test'
30+
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
3231
}
3332

3433
tasks.named('test') {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.systemdesign.slidingwindowlog.common.common;
2+
3+
import com.fasterxml.jackson.annotation.JsonInclude;
4+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
5+
import com.fasterxml.jackson.databind.ObjectMapper;
6+
import org.springframework.context.annotation.Bean;
7+
import org.springframework.context.annotation.Configuration;
8+
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
9+
import org.springframework.data.redis.core.ReactiveRedisTemplate;
10+
import org.springframework.data.redis.serializer.*;
11+
12+
@Configuration
13+
public class RedisConfig {
14+
15+
@Bean
16+
public ReactiveRedisTemplate<String, Object> reactiveRedisTemplate(ReactiveRedisConnectionFactory connectionFactory) {
17+
ObjectMapper objectMapper = new ObjectMapper();
18+
objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
19+
objectMapper.activateDefaultTyping(objectMapper.getPolymorphicTypeValidator(), ObjectMapper.DefaultTyping.EVERYTHING, JsonTypeInfo.As.PROPERTY); // 모든 객체 타입에 대한 정보를 포함
20+
21+
RedisSerializer<Object> redisSerializer = new GenericJackson2JsonRedisSerializer(objectMapper);
22+
23+
RedisSerializationContext<String, Object> context = RedisSerializationContext
24+
.<String, Object>newSerializationContext(RedisSerializer.string())
25+
.value(redisSerializer)
26+
.hashValue(redisSerializer)
27+
.build();
28+
29+
return new ReactiveRedisTemplate<>(connectionFactory, context);
30+
}
31+
}

‎src/main/resources/application.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spring:
2+
data:
3+
redis:
4+
host: localhost
5+
port: 6379

0 commit comments

Comments
 (0)
Please sign in to comment.