https://github.com/sokomishalov/lokk
Kotlin/JVM coroutine-based distributed locks
https://github.com/sokomishalov/lokk
cluster coroutines kotlin locks mongo redis
Last synced: 5 months ago
JSON representation
Kotlin/JVM coroutine-based distributed locks
- Host: GitHub
- URL: https://github.com/sokomishalov/lokk
- Owner: sokomishalov
- License: apache-2.0
- Created: 2020-01-14T15:57:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-03-17T02:17:22.000Z (over 5 years ago)
- Last Synced: 2025-04-07T03:36:56.203Z (about 1 year ago)
- Topics: cluster, coroutines, kotlin, locks, mongo, redis
- Language: Kotlin
- Homepage:
- Size: 57.6 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
Lokk
========
~~Here should be some modern logo~~
[](https://www.apache.org/licenses/LICENSE-2.0.txt)
[](https://jitpack.io/#sokomishalov/lokk)
## Overview
Kotlin/JVM coroutine-based distributed locks
## Why not [ShedLock](https://github.com/lukas-krecan/ShedLock)?
There are some simple advantages:
- Core API is build on coroutines (suspend-able methods), providers are implementing them with **non-blocking** APIs
- There are no optional hell inside core, result is an instance of sealed class
- Kotlin DSL api
Disadvantages:
- Much less implementations are done :( (plz help and contribute!)
## Distribution
Library with modules are available only from `jitpack` so far:
```xml
jitpack.io
https://jitpack.io
```
## Usage
Usage as simple as is - just instantiate required provider and use it like this:
```kotlin
val lokkProvider = /*...*/
lokkProvider.withLokk(atLeastFor = Duration.ofMinutes(10), atMostFor = Duration.ofHours(1)) {
// do some magic
}
```
There are several jvm lokk implementations so far
- [lokk-redis-lettuce](#redis-with-reactive-Lettuce)
- [lokk-mongo-reactive-streams](#mongo-with-reactive-streams-driver)
## Redis with reactive Lettuce
Import a dep:
```xml
com.github.sokomishalov
lokk-redis-lettuce
${lokk.version}
```
Then use [this implementation](./providers/redis/lokk-redis-lettuce/src/main/kotlin/ru/sokomishalov/lokk/provider/RedisLettuceLokkProvider.kt):
```kotlin
val lokkProvider = RedisLettuceLokkProvider(client = RedisClient.create())
```
## Mongo with reactive streams driver
Import a dep:
```xml
com.github.sokomishalov
lokk-mongo-reactive-streams
${lokk.version}
```
Then use [this implementation](./providers/mongo/lokk-mongo-reactive-streams/src/main/kotlin/ru/sokomishalov/lokk/provider/MongoReactiveStreamsLokkProvider.kt):
```kotlin
val lokkProvider = MongoReactiveStreamsLokkProvider(client = MongoClients.create())
```