Skip to content
/ kedis Public

Redis client library for Kotlin Multiplatform (JVM + Native)

License

Notifications You must be signed in to change notification settings

domgew/kedis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jan 26, 2024
f2d5d23 · Jan 26, 2024

History

24 Commits
Jan 26, 2024
Jan 7, 2024
Jan 26, 2024
Jan 7, 2024
Jan 26, 2024
Jan 26, 2024
Jan 13, 2024
Jan 26, 2024
Jan 19, 2024
Jan 26, 2024
Jan 13, 2024
Jan 26, 2024
Jan 7, 2024
Jan 7, 2024
Jan 26, 2024

Repository files navigation

Kedis

Latest Tag Publish Test Kotlin Licence: MIT

Kedis is a Redis client library for Kotlin Multiplatform (JVM + Native). This is possible via Ktor Network, which provides native and JVM sockets with a unified interface.

Installation

repositories {
    // ...
    maven("https://maven.pkg.github.com/domgew/kedis")
    // ...
}
dependencies {
    // ...

    implementation("io.github.domgew:kedis:<current_version>")

    // OR just for JVM:
    implementation("io.github.domgew:kedis-jvm:<current_version>")

    // ...
}

Targets

Supported Targets:

  • JVM
  • Native: Linux X64
  • Native: Linux ARM64
  • Native: macOS X64
  • Native: macOS ARM64

Potential Future Targets (mostly currently no Ktor Network support):

  • Native: MinGW X64
  • JS: NodeJS
  • JVM: GraalVM Native

Non-Targets - Never Coming:

  • Native 32 bit targets
  • Native consumer targets (android, iOS, tvOS, watchOS, ...)
  • JS: Browser

Library Comparison

Kedis Kreds
Automated Integration Tests
JVM Support
Native Linux X64 Support
Native Linux ARM64 Support
Native macOS X64 Support
Native macOS ARM64 Support
Host + Port Support
UNIX Socket Support
Binary Data Support
Mature
Full-Featured
Pub-Sub Support
GraalVM Native Support
Exclusive Configuration Compile Time / Sealed Polymorthism Run Time / Builder Exception
Responses Strictly Typed Semi-Raw
Networking Ktor Network (Kotlin) Netty (Java)
Redis Protocol (En-/Decoding) Custom (Kotlin) Netty (Java)
Redis Protocol (Interfacing) Custom (Kotlin) Custom (Kotlin)

Examples

See example project.

Caching concept ("get or generate") with gradual service degradation:

  • Try to connect to the Redis server (KedisClient.connect) - here you would already see, whether the server is reachable, if not, fall back to generation -> EXIT with generation
  • Try to get the value for the key (KedisClient.get/getBinary) - if it is null, it does not exist - it could however fail under some circumstances, so use a try-catch block -> EXIT with generation
  • When a non-null value was retrieved, you can return it (maybe close the connection/client (KedisClient.close) - with dependency injection request scopes, this might however not be desired) -> EXIT
  • Otherwise, use a callback to generate the value (e.g. call an external API)
  • Try to set the value for the key (KedisClient.set/setBinary) with the desired options (e.g. time-to-live, value replacement, ...) - this might however fail under some circumstances
  • Return the generated value (maybe close the connection)