Mock Jedis
Mock Jedis is a library for mocking out Jedis clients. It's useful for testing your code without actually having a live redis server up. Currently, mock-jedis supports pipelining and all the basic Jedis commands, but if you find missing functionality you're welcome to submit a pull request.
What's different
This repo enhance the original one (50onRed) with a more complete list operation support (LPOP LPUSH RPUSH RPOP).
In addition, this repo uses its own maven central url for the new features.
dependencies {
testCompile 'com.github.xuanyue202:mock-jedis:0.4.1'
}
Compile
with gradle (preferred method):
gradle build
Adding mock-jedis to your project
Add it as a dependency to your project.
Here's a sample gradle script that will pull mock-jedis 0.4.1 from maven-central
buildscript {
repositories {
mavenCentral()
}
}
apply plugin: 'java'
dependencies {
testCompile 'com.github.xuanyue202:mock-jedis:0.4.1'
}
Sample maven dependency definition:
<dependency>
<groupId>com.fiftyonred</groupId>
<artifactId>mock-jedis</artifactId>
<version>0.4.0</version>
<type>jar</type>
<scope>test</scope>
</dependency>
Using mock-jedis
Jedis j = new MockJedis("test");
j.set("test", "123");
assertEquals("123", j.get("test"));
Supported Commands
Currently the following commands are supported by mock-jedis
- KEYS: DEL DUMP EXISTS EXPIRE EXPIREAT KEYS PERSIST PEXPIRE PEXPIREAT PTTL RANDOMKEY RENAME RENAMENX RESTORE TTL TYPE
- STRINGS: APPEND DECR DECRBY GET GETSET INCR INCRBY INCRBYFLOAT MGET MSET MSETNX PSETEX SET SETEX SETNX STRLEN
- HASHES: HDEL HEXISTS HGET HGETALL HINCRBY HINCRBYFLOAT HKEYS HLEN HMGET HMSET HSET HSETNX HVALS
- LISTS: LLEN LPOP LPUSH RPUSH RPOP
- SETS: SADD SCARD SDIFF SDIFFSTORE SINTER SINTERSTORE SISMEMBER SMEMBERS SMOVE SPOP SRANDMEMBER SREM SUNION SUNIONSTORE
- CONNECTIONS: ECHO PING SELECT QUIT
- SERVER: DBSIZE FLUSHALL FLUSHDB
- PIPELINES
Unsupported Things
- All commands not listed above