Skip to content

sapotero/dice-db-client

Repository files navigation

DiceDB Kotlin Client

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.

✨ Features

  • 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.

📦 Installation (via JitPack)

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.


🚀 Example Usage

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")
    }
}

📘 Supported Commands

All commands are accessible as Command.Xyz(...), returning typed Response.XyzRes.

🔑 String Commands

📈 Numeric Commands

🧮 Hash Commands

🧠 Reactive (Watch) Commands

📊 Sorted Set Commands


🛠 Command Example

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.


🧪 Testing

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

📄 License

MIT License. © 2025 @sapotero — Contributions welcome.


About

dice-db

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages