11package com .ai .lawyer .global .config ;
22
33import org .springframework .beans .factory .annotation .Value ;
4+ import org .springframework .boot .autoconfigure .condition .ConditionalOnProperty ;
45import org .springframework .context .annotation .Configuration ;
56import org .springframework .context .event .ContextClosedEvent ;
67import org .springframework .context .event .ContextRefreshedEvent ;
78import org .springframework .context .event .EventListener ;
89import redis .embedded .RedisServer ;
910
1011import jakarta .annotation .PreDestroy ;
11- import java .io .IOException ;
1212
1313@ Configuration
14+ @ ConditionalOnProperty (name = "spring.data.redis.embedded" , havingValue = "true" , matchIfMissing = true )
1415public class EmbeddedRedisConfig {
1516
1617 @ Value ("${spring.data.redis.port:6379}" )
1718 private int redisPort ;
1819
19- @ Value ("${spring.data.redis.embedded:true}" )
20- private boolean embedded ;
21-
2220 private RedisServer redisServer ;
2321
2422 @ EventListener (ContextRefreshedEvent .class )
2523 public void startRedis () {
26- if (embedded ) {
27- try {
28- redisServer = RedisServer .builder ()
24+ try {
25+ redisServer = RedisServer .builder ()
2926 .port (redisPort )
30- .setting ("maxmemory 128M" ) // 메모리 제한 설정
27+ .setting ("maxmemory 128M" )
3128 .build ();
32-
33- if (!redisServer .isActive ()) {
34- redisServer .start ();
35- System .out .println ("=== Embedded Redis 서버가 포트 " + redisPort + "에서 시작되었습니다 ===" );
36- }
37- } catch (Exception e ) {
38- System .err .println ("=== Embedded Redis 서버 시작 실패: " + e .getMessage () + " ===" );
39- throw e ;
29+
30+ if (!redisServer .isActive ()) {
31+ redisServer .start ();
32+ System .out .println ("=== Embedded Redis 서버가 포트 " + redisPort + "에서 시작되었습니다 ===" );
4033 }
34+ } catch (Exception e ) {
35+ System .err .println ("=== Embedded Redis 서버 시작 실패: " + e .getMessage () + " ===" );
4136 }
4237 }
4338
4439 @ PreDestroy
4540 @ EventListener (ContextClosedEvent .class )
4641 public void stopRedis () {
47- if (embedded && redisServer != null && redisServer .isActive ()) {
42+ if (redisServer != null && redisServer .isActive ()) {
4843 redisServer .stop ();
4944 System .out .println ("=== Embedded Redis 서버가 중지되었습니다 ===" );
5045 }
5146 }
52- }
47+ }
0 commit comments