raycon / til

Today I Learned
MIT License
16 stars 3 forks source link

Windows 에서 Embedded Redis 실행시 에러가 발생할 경우 #109

Open raycon opened 2 years ago

raycon commented 2 years ago
  1. 포트가 사용중일 경우 : 컴퓨터를 재시작하는게 제일 빠름
  2. 메모리 설정이 없을 경우 : setting("maxmemory 128M") 코드를 추가함
// https://github.com/kstyrc/embedded-redis/issues/51#issuecomment-318221233

@Configuration
@Profile("test")
public class EmbeddedRedisServer {

    @Value("${spring.redis.port:6380}")
    private int redisPort;

    private RedisServer redisServer;

    @PostConstruct
    public void startRedis() throws IOException, URISyntaxException {
        //redisPort = org.springframework.util.SocketUtils.findAvailableTcpPort(6380);
        //RedisExecProvider customRedisExec = RedisExecProvider.defaultProvider().override
        //        (OsArchitecture.detect().os(), OsArchitecture.detect().arch(), "redis-server-2.8.19.exe");

        redisServer = RedisServer.builder()
                .port(redisPort)
                //.redisExecProvider(customRedisExec) //com.github.kstyrc (not com.orange.redis-embedded)
                .setting("maxmemory 128M") //maxheap 128M
                .build();
        redisServer.start();
    }

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