Skip to content

Commit 9f87361

Browse files
committed
Ref: 내장 Redis 의존성 변경
1 parent 67f67cc commit 9f87361

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

build.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ dependencies {
6666

6767
// Redis
6868
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-
69+
implementation("com.github.codemonstur:embedded-redis:1.4.3")
7370
}
7471

7572
tasks.withType<Test> {

src/main/java/com/back/global/config/EmbeddedRedisConfig.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.springframework.context.annotation.Configuration;
66
import org.springframework.context.annotation.Profile;
77
import redis.embedded.RedisServer;
8-
import redis.embedded.RedisServerBuilder;
98

109
import java.io.IOException;
1110
import java.net.ServerSocket;
@@ -24,26 +23,28 @@ public class EmbeddedRedisConfig {
2423
private int port;
2524

2625
@PostConstruct
27-
public void startRedis() throws IOException {
28-
port = findAvailablePort();
29-
redisServer = new RedisServerBuilder()
30-
.port(port)
31-
.setting("maxheap 256M")
32-
.build();
33-
redisServer.start();
34-
35-
// 동적으로 찾은 포트를 Spring 환경 변수에 반영
36-
System.setProperty("spring.data.redis.port", String.valueOf(port));
26+
public void startRedis() {
27+
try {
28+
this.port = findAvailablePort();
29+
this.redisServer = new RedisServer(port);
30+
this.redisServer.start();
31+
System.setProperty("spring.data.redis.port", String.valueOf(port));
32+
} catch (IOException e) {
33+
throw new IllegalStateException("Failed to start embedded Redis", e);
34+
}
3735
}
3836

3937
@PreDestroy
4038
public void stopRedis() {
41-
if (redisServer != null) {
42-
redisServer.stop();
39+
try {
40+
if (redisServer != null && redisServer.isActive()) {
41+
redisServer.stop();
42+
}
43+
} catch (IOException e) {
44+
throw new IllegalStateException("Failed to stop embedded Redis", e);
4345
}
4446
}
4547

46-
// 사용 가능한 포트를 찾는 유틸리티 메서드
4748
private int findAvailablePort() {
4849
try (ServerSocket socket = new ServerSocket(0)) {
4950
socket.setReuseAddress(true);

0 commit comments

Comments
 (0)