refactor(Test): 内嵌redis

This commit is contained in:
禾几海
2020-08-14 17:16:19 +08:00
parent 6eb7d01875
commit 2fce2d8a1c
2 changed files with 44 additions and 0 deletions

View File

@@ -175,6 +175,13 @@
<artifactId>h2</artifactId>
<version>1.4.200</version>
</dependency>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -0,0 +1,37 @@
package cn.celess.blog;
import redis.embedded.RedisServer;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
/**
* @author : xiaohai
* @date : 2020/08/14 16:20
*/
@Component
public class RedisServerMock {
private RedisServer redisServer;
/**
* 构造方法之后执行.
*
* @throws IOException e
*/
@PostConstruct
public void startRedis() throws IOException {
redisServer = new RedisServer(6379);
redisServer.start();
}
/**
* 析构方法之后执行.
*/
@PreDestroy
public void stopRedis() {
redisServer.stop();
}
}