Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sokomishalov/lokk
Kotlin/JVM coroutine-based distributed locks
https://github.com/sokomishalov/lokk
cluster coroutines kotlin locks mongo redis
Last synced: 21 days 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 (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-17T02:17:22.000Z (over 3 years ago)
- Last Synced: 2024-10-07T17:01:11.593Z (about 1 month ago)
- Topics: cluster, coroutines, kotlin, locks, mongo, redis
- Language: Kotlin
- Homepage:
- Size: 57.6 KB
- Stars: 2
- Watchers: 2
- 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~~[![Apache License 2](https://img.shields.io/badge/license-ASF2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.txt)
[![](https://jitpack.io/v/sokomishalov/lokk.svg)](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 apiDisadvantages:
- 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:
```xmlcom.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:
```xmlcom.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())
```