Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

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 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())
```