Skip to content

Commit

Permalink
edit embedded redis config
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-khg committed Dec 12, 2023
1 parent e8030d2 commit c2e0e73
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,33 @@

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import redis.embedded.RedisServer;

@TestConfiguration
public class EmbeddedRedisConfiguration {
private RedisServer redisServer;
private final static Logger logger = LoggerFactory.getLogger(EmbeddedRedisConfiguration.class);

public EmbeddedRedisConfiguration(@Value("${spring.data.redis.port}") int port) {
this.redisServer = new RedisServer(port);
}

@PostConstruct
public void startRedis() {
redisServer.start();
try {
redisServer.start();
} catch (Exception e) {
logger.error("error = {}", e.getMessage());
}
}

@PreDestroy
public void stopRedis() {
if(redisServer != null) {
if (redisServer != null) {
redisServer.stop();
}
}
Expand Down

0 comments on commit c2e0e73

Please sign in to comment.