1+ package com .back .global .config ;
2+
3+ import jakarta .annotation .PostConstruct ;
4+ import jakarta .annotation .PreDestroy ;
5+ import org .springframework .beans .factory .annotation .Value ;
6+ import org .springframework .context .annotation .Configuration ;
7+ import org .springframework .context .annotation .Profile ;
8+ import redis .embedded .RedisServer ;
9+
10+ import java .io .IOException ;
11+
12+ /**
13+ * 로컬 및 테스트 환경 임베디드 Redis 설정
14+ * - test 프로필에서만 활성화
15+ */
16+ @ Configuration
17+ @ Profile ("test" )
18+ public class EmbeddedRedisConfig {
19+
20+ @ Value ("${spring.data.redis.port}" )
21+ private int redisPort ;
22+
23+ private RedisServer redisServer ;
24+
25+ @ PostConstruct
26+ public void startRedis () {
27+ try {
28+ redisServer = new RedisServer (redisPort );
29+ redisServer .start ();
30+ System .out .println ("========================================" );
31+ System .out .println ("Embedded Redis started on port " + redisPort );
32+ System .out .println ("========================================" );
33+ } catch (IOException e ) {
34+ System .err .println ("Embedded Redis start failed: " + e .getMessage ());
35+ System .err .println ("This is OK if external Redis is already running" );
36+ }
37+ }
38+
39+ @ PreDestroy
40+ public void stopRedis () {
41+ try {
42+ if (redisServer != null && redisServer .isActive ()) {
43+ redisServer .stop ();
44+ System .out .println ("========================================" );
45+ System .out .println ("Embedded Redis stopped" );
46+ System .out .println ("========================================" );
47+ }
48+ } catch (Exception e ) {
49+ System .err .println ("Error stopping embedded Redis: " + e .getMessage ());
50+ }
51+ }
52+ }
0 commit comments