3 import java.io.IOException;
4 import java.io.InputStream;
5 import java.util.Properties;
7 import org.junit.rules.ExternalResource;
9 import redis.clients.jedis.Jedis;
12 * Drops the entire key space of a redis instance before and after a test run.
14 public class RedisCleaner extends ExternalResource {
16 private Properties properties;
20 protected void before() throws IOException {
21 properties = loadProperties();
23 String host = properties.getProperty("redis.host");
24 int port = Integer.parseInt(properties.getProperty("redis.port"));
25 jedis = new Jedis(host, port);
27 // completely clear the redis instance before each test
32 protected void after() {
33 // completely clear the redis instance after each test
37 // close the connection pool
43 * @return loaded redis properties
45 public Properties getProperties() {
49 public Jedis getJedis() {
53 private Properties loadProperties() throws IOException {
54 Properties properties = new Properties();
55 try (InputStream in = getClass().getClassLoader().getResourceAsStream("redis.properties")) {