DiceDB is an open-source, in-memory database that is reactive (pushes updates to subscribed queries) and optimized for modern hardware. This Kotlin client provides a strongly-typed, coroutine-friendly API for interacting with DiceDB.
- ✅ Strong Typing: All commands and responses use Kotlin data and sealed classes.
- ✅ Coroutine Support: Non-blocking suspend functions.
- ✅ Clean API: DSL-style commands like
Command.Set("k", "v")with type-safe responses. - ✅ Extensible: Easily add new commands.
- ✅ Testable: Full test suite covering edge cases.
In settings.gradle.kts:
dependencyResolutionManagement {
repositories {
mavenCentral()
maven(url = "https://jitpack.io")
}
}In your build.gradle.kts:
dependencies {
implementation("com.github.sapotero:dice-db-client:<version>")
}Replace <version> with a tag, commit hash, or master-SNAPSHOT.
suspend fun main() {
val client = DiceDBClient("localhost", 7379)
with(client) {
val setResp: Response.SETRes = fire(Command.Set("k1", "v1"))
val getResp: Response.GETRes = fire(Command.Get("k1"))
println("SET: $setResp, GET: $getResp")
}
}All commands are accessible as Command.Xyz(...), returning typed Response.XyzRes.
- HANDSHAKE
- UNWATCH
- GET.WATCH
- HGET.WATCH
- HGETALL.WATCH
- ZCARD.WATCH
- ZCOUNT.WATCH
- ZRANGE.WATCH
- ZRANK.WATCH
data class Get(val key: String) : Command<Response.GETRes>() {
override fun toProto() = ProtoCommand("GET", listOf(key))
}All commands are sealed classes and implement a .toProto() method to serialize them into the DiceDB wire format.
This client has been tested extensively using integration test cases with real command inputs and expected results. Commands are verified for:
- Correct syntax serialization
- Error handling
- Expiration logic
- Numeric overflows and type mismatches
MIT License. © 2025 @sapotero — Contributions welcome.