Skip to content

Commit ebbd303

Browse files
committed
Chore: Redis 설정 추가
1 parent 609d106 commit ebbd303

File tree

5 files changed

+95
-0
lines changed

5 files changed

+95
-0
lines changed

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ dependencies {
6363
testImplementation("org.springframework.boot:spring-boot-starter-test")
6464
testImplementation("org.springframework.security:spring-security-test")
6565
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
66+
67+
// Redis
68+
implementation("org.springframework.boot:spring-boot-starter-data-redis")
69+
implementation("it.ozimov:embedded-redis:0.7.3") {
70+
exclude(group = "org.slf4j", module = "slf4j-simple")
71+
}
72+
6673
}
6774

6875
tasks.withType<Test> {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package com.back.global.config;
2+
3+
import jakarta.annotation.PostConstruct;
4+
import jakarta.annotation.PreDestroy;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.context.annotation.Profile;
7+
import redis.embedded.RedisServer;
8+
import redis.embedded.RedisServerBuilder;
9+
10+
import java.io.IOException;
11+
12+
/**
13+
* Embedded Redis 설정 클래스
14+
* - 개발 및 테스트 환경에서만 활성화 (dev, test 프로파일)
15+
* - 애플리케이션 시작 시 내장 Redis 서버 시작
16+
* - 애플리케이션 종료 시 내장 Redis 서버 중지
17+
*/
18+
@Configuration
19+
@Profile({"dev", "test"})
20+
public class EmbeddedRedisConfig {
21+
22+
private RedisServer redisServer;
23+
24+
public EmbeddedRedisConfig() throws IOException {
25+
this.redisServer = new RedisServerBuilder()
26+
.port(6379)
27+
.setting("maxheap 256M")
28+
.build();
29+
}
30+
31+
@PostConstruct
32+
public void startRedis() {
33+
redisServer.start();
34+
}
35+
36+
@PreDestroy
37+
public void stopRedis() {
38+
if (redisServer != null) {
39+
redisServer.stop();
40+
}
41+
}
42+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.back.global.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.data.redis.connection.RedisConnectionFactory;
6+
import org.springframework.data.redis.core.RedisTemplate;
7+
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
8+
import org.springframework.data.redis.serializer.StringRedisSerializer;
9+
10+
/**
11+
* Redis 설정 클래스
12+
*/
13+
@Configuration
14+
public class RedisConfig {
15+
16+
/**
17+
* RedisTemplate 설정
18+
* - Key: String
19+
* - Value: JSON (Jackson)
20+
*/
21+
@Bean
22+
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
23+
RedisTemplate<String, Object> template = new RedisTemplate<>();
24+
template.setConnectionFactory(connectionFactory);
25+
26+
// Key: String
27+
template.setKeySerializer(new StringRedisSerializer());
28+
template.setHashKeySerializer(new StringRedisSerializer());
29+
30+
// Value: JSON
31+
template.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
32+
template.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
33+
34+
return template;
35+
}
36+
}

src/main/resources/application-dev.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ spring:
55
username: sa
66
password:
77

8+
data:
9+
redis:
10+
host: localhost
11+
port: 6379
12+
813
config:
914
import: optional:file:.env[.properties]
1015

src/main/resources/application-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ spring:
55
username: sa
66
password:
77

8+
data:
9+
redis:
10+
host: localhost
11+
port: 6379
12+
813
jwt:
914
secret: test-jwt-secret-key-12345678901234567890
1015
access-token-expiration: ${JWT_ACCESS_TOKEN_EXPIRATION:1800} # 30분 (초 단위)

0 commit comments

Comments
 (0)