kedis
0.0.12indexedRedis client library facilitates communication with Redis servers using network sockets. Supports automated integration tests, native Linux and macOS compatibility, strict typing, and custom protocol interfacing.
Redis client library facilitates communication with Redis servers using network sockets. Supports automated integration tests, native Linux and macOS compatibility, strict typing, and custom protocol interfacing.
Kedis is a Redis client library for Kotlin Multiplatform (JVM + Native). This is possible via Ktor Network sockets, which provides native and JVM sockets with a unified interface.
dependencies {
// ...
implementation("io.github.domgew:kedis:<current_version>")
// optional:
implementation("io.github.domgew:kedis-lock:<current_version>")
// OR just for JVM:
implementation("io.github.domgew:kedis-jvm:<current_version>")
// optional:
implementation("io.github.domgew:kedis-lock-jvm:<current_version>")
// ...
}
repositories {
mavenCentral()
// ...
}
See Dokka-generated docs.
For available commands see the documentation of the commands package and the KedisConfiguration for the available configuration options.
KedisClient.builder {
// OR: unixSocket
hostAndPort(
host = "127.0.0.1",
port = ,
)
autoAuth(
password = ,
username = ,
)
connectTimeout = milliseconds
keepAlive =
databaseIndex =
}
.use { client ->
testValue = client.execute(
KedisValueCommands.(
key = ,
),
)
?.let {
}
?:
println()
}
Additional library (io.github.domgew:kop) needed.
KotlinObjectPool(
KotlinObjectPoolConfig(
maxSize = 3,
keepAliveFor = 2.minutes,
strategy = KotlinObjectPoolStrategy.LIFO, // OR: FIFO
),
) {
// OR: KedisClient(configuration)
KedisClient.builder {
hostAndPort("127.0.0.1", 6379)
noAutoAuth()
connectTimeout = milliseconds
keepAlive =
}
}
.use { pool ->
testValue = pool.withObject { client ->
client.execute(
KedisValueCommands.(
key = ,
),
)
}
?.let {
}
?:
println()
}
dependencies {
implementation("io.github.domgew:kedis-lock:<current_version>")
}
KedisClient.builder {
hostAndPort(
host = "127.0.0.1",
)
connectTimeout = 250.milliseconds
}
.use { client ->
val locker = client.locker()
val dynamicLock = locker.asDynamicLock()
dynamicLock.withTryLock(
key = "my-lock",
maxLockFor = 10.seconds,
default = {
Exception()
},
) {
println()
}
lock = locker.asLock(
key = ,
)
lock.withTryLock(
maxLockFor = seconds,
default = {
Exception()
},
) {
println()
}
}
Supported Targets:
Potential Future Targets (mostly currently no Ktor Network support):
Non-Targets - Never Coming:
See example project.
Caching concept ("get or generate") with gradual service degradation:
null, it does not exist - it could however
fail under some circumstances, so use a try-catch block -> EXIT with generation---
title: Get or Generate
---
flowchart
start([Value requested])
isAvailable{Is Redis available?}
getFromCache[Get from cache]
generateBeforeExit[Generate]
generateBeforeWrite[Generate]
writeToCache[Write to cache]
hasCachedValue{Has cached value?}
returnValue([Return value])
exitWithError([Exit with error])
start --> isAvailable
isAvailable -- no --> generateBeforeExit
isAvailable -- yes --> getFromCache
generateBeforeExit -- success --> returnValue
generateBeforeExit -- error --> exitWithError
getFromCache -- error --> generateBeforeExit
getFromCache -- success --> hasCachedValue
hasCachedValue -- no --> generateBeforeWrite
hasCachedValue -- yes --> returnValue
generateBeforeWrite -- success --> writeToCache
generateBeforeWrite -- error --> exitWithError
writeToCache -- error --> returnValue
writeToCache -- success --> returnValue
KedisClient(
configuration = KedisConfiguration(
// OR: KedisConfiguration.Endpoint.UnixSocket(path)
endpoint = KedisConfiguration.Endpoint.HostPort(
host = "127.0.0.1",
port = 6379, // optional, 6379 is the default
),
// OR: KedisConfiguration.Authentication.NoAutoAuth
authication = KedisConfiguration.Authentication.AutoAuth(
password = "secret",
username = "admin", // optional
),
connectionTimeout = 250.milliseconds,
keepAlive = true, // optional, true is the default
databaseIndex = 1, // optional, 0 is the default
),
)
.use { client ->
val testValue = client.execute(
KedisValueCommands.get(
key = "test",
),
)
?.let {
"'$it'"
}
?: "NULL"
println("Test value: $testValue")
}
| 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 | ✓ | ✗ |
| Stable Authentication | ✓ (with AutoAuth) | ✗ (errors when reconnecting) |
| Mature | ✗ | ✓ |
| Full-Featured | ✗ | ✓ |
| Pub-Sub Support | ✗ | ✓ |
| Pipelining 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) |
Surfaced from shared tags and platforms — no rankings paid for.