ClauDB is a REDIS implementation in Java. At the moment is in development and only implements a small subset of commands and features. The objetive is implement a full functional one-to-one replacement for REDIS (2.8 branch).
You will probably wonder why I do this, the answer is I do it Just For Fun.
Initially I called this project TinyDB, but there's another project with the same name, so, I've decided to chage to ClaudDB.
Clau is 🔑 in Valencià, a language spoken in eastern Spain, and ClauDB is a key-value database.
Server
- FLUSHDB
- INFO
- TIME
- SYNC
- SLAVEOF
- ROLE
Connection
- ECHO
- PING
- QUIT
- SELECT
Key
- DEL
- EXISTS
- KEYS
- RENAME
- TYPE
- EXPIRE
- PERSIST
- TTL
- PTTL
String
- APPEND
- DECRBY
- DECR
- GET
- GETSET
- INCRBY
- INCR
- MGET
- MSET
- MSETNX
- SET (with NX, PX, NX and XX options)
- SETEX
- SETNX
- STRLEN
Hash
- HDEL
- HEXISTS
- HGETALL
- HGET
- HKEYS
- HLEN
- HMGET
- HMSET
- HSET
- HVALS
List
- LPOP
- LPUSH
- LINDEX
- LLEN
- LRANGE
- LSET
- RPOP
- RPUSH
Set
- SADD
- SCARD
- SDIFF
- SINTER
- SISMEMBER
- SMEMBERS
- SPOP
- SRANDMEMBER
- SREM
- SUNION
Sorted Set
- ZADD
- ZCARD
- ZRANGEBYSCORE
- ZRANGE
- ZREM
- ZREVRANGE
- ZINCRBY
Pub/Sub
- SUBSCRIBE
- UNSUBSCRIBE
- PSUBSCRIBE
- PUNSUBSCRIBE
- PUBLISH
Transactions
- MULTI
- EXEC
- DISCARD
Scripting
- EVAL
- EVALSHA
- SCRIPT LOAD
- SCRIPT EXISTS
- SCRIPT FLUSH
ClauDB is implemented using Java8. Is single thread, like REDIS. It uses asynchronous IO (netty) and reactive programing paradigm (rxjava).
Requests come from IO threads and enqueues to rxjava single thread scheduler. Then IO thread is free to process another request. When request is done, the response is sended to client asyncronously. Then, every request is managed one by one, in a single thread, so there's no concurrency issues to care about.
Now only implements a subset of REDIS commands, but is usable.
ClauDB also supports persistence compatible with REDIS, RDB dumps and AOF journal. It can create
compatible RDB files you can load in a REDIS server. Removed since 2.0 version
Now ClauDB support master/slave replication, a master can have multiple slaves, but at the moment slaves can't have slaves.
Also implements partially the Pub/Sub subsystem.
The RDB file format support has been dropped and replaced with h2 MVStore.
This allows ClauDB to have file persistence and off heap memory support.
Another important change, now ClauDB has been splited in several subprojects:
- claudb-lib: implementation of the server and commands.
- claudb-app: command line application to run standalone server and client.
- claudb-junit4: implements a Junit4 compatible @Rule to use in junit4 based tests. Example
- claudb-junit5: implements a Junit5 compatible extension to use in junit5 based tests. Example
Performance is quite good, not as good as REDIS, but it's good enough for Java.
This is ClauDB
$ redis-benchmark -t set,get -h localhost -p 7081 -n 100000 -q
SET: 82576.38 requests per second, p50=0.303 msec
GET: 93896.71 requests per second, p50=0.287 msec
And this is REDIS
$ redis-benchmark -t set,get -h localhost -p 6379 -n 100000 -q
SET: 148148.14 requests per second, p50=0.167 msec
GET: 147710.48 requests per second, p50=0.175 msec
In my laptop (Intel Core i7-1065G7, with 32G of RAM, running linux)
You need to clon the repo:
$ git clone https://github.com/tonivade/claudb.git
ClauDB uses Gradle as building tool, but you don't need Gradle installed, just type:
$ ./gradlew build
This scripts automatically download Gradle and then runs the tasks.
Or if you have Gradle installed, just type
$ gradle build
Create all-in-one jar
$ ./gradlew fatJar
You can create your own docker images for ClauDB using the provided Dockerfile
$ docker build -t claudb .
And then run the image
$ docker run -p 7081:7081 claudb
You can start a new server listening in default port 7081.
$ wget https://repo1.maven.org/maven2/com/github/tonivade/claudb-app/2.0.1/claudb-app-2.0.1-all.jar
$ java -jar claudb-2.0.1-all.jar
or using jgo utility
$ jgo com.github.tonivade:claudb-app:2.0.1:com.github.tonivade.claudb.Server
Parameters:
Option Description
------ -----------
-N enable keyspace notifications (experimental)
-O enable off heap memory (experimental)
-P [String: file name] enable persistence (experimental) (default: ./claudb.data)
-V verbose mode
-h <String: host> define listen host (default: localhost)
--help print help
-p <Integer: port> define listen port (default: 7081)
Also you can use inside your project using Maven
<dependency>
<groupId>com.github.tonivade</groupId>
<artifactId>claudb</artifactId>
<version>2.0.1</version>
</dependency>
Or gradle
compile 'com.github.tonivade:claudb:2.0.1'
Or embed in your source code
RespServer server = ClauDB.builder().host("localhost").port(7081).build();
server.start();
Now is possible to generate a native image thanks to graalvm. You can generate one with this command:
$ ./gradlew clean nativeImage
Some features are not available like lua runtime and offheap memory.
- Ziplist and Maplist encoding not implemented yet.
- Master/Slave replication improvements. Slave with Slaves
- Partitioning?
- Clustering?
- Geo Commands
ClauDB is released under MIT License