Redis Mock is a simple in-memory mock of redis for java testing. It allows you to test any behaviour dependent on redis without having to deploy an instance of redis
Add it as a dependency in Maven as:
<dependency>
<groupId>ai.grakn</groupId>
<artifactId>redis-mock</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<repositories>
<repository>
<id>releases</id>
<url>https://maven.grakn.ai/content/repositories/releases/</url>
</repository>
</repositories>
Create a redis server and bind it to jedis:
private static RedisServer server = null;
@Before
public void before() throws IOException {
server = RedisServer.newRedisServer(); // bind to a random port
server.start();
}
@Test
public void test() {
...
Jedis jedis = new Jedis(server.getHost(), server.getBindPort());
...
}
@After
public void after() {
server.stop();
server = null;
}
From here test as needed
RedisServer master = newRedisServer();
RedisServer slave = newRedisServer();
master.setSlave(slave);
We can make a RedisServer close connection after every serveral commands. This will cause a connection exception for clients.
RedisServer server = RedisServer.newRedisServer();
ServiceOptions options = new ServiceOptions();
options.setCloseSocketAfterSeveralCommands(3);
server.setOptions(options);
server.start();
strlen
get
append
exists
set
ttl
decrby
pfadd
pfmerge
mget
mset
getset
del
expireat
pexpireat
setex
psetex
setnx
setbit
getbit
pttl
expire
pexpire
incr
incrby
decr
pfcount