-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathEmbededRedis.java
More file actions
31 lines (24 loc) · 801 Bytes
/
EmbededRedis.java
File metadata and controls
31 lines (24 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package geektime.im.lecture.redis;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import redis.embedded.RedisServer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
@Component
public class EmbededRedis {
@Value("${spring.redis.port}")
private int redisPort;
@Value("${spring.redis.maxheap}")
private String maxheap;
private RedisServer redisServer;
@PostConstruct
public void startRedis() throws IOException {
redisServer = RedisServer.builder().setting("maxheap "+maxheap).port(redisPort).setting("bind localhost").build();
redisServer.start();
}
@PreDestroy
public void stopRedis() {
redisServer.stop();
}
}