Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/x-punch/x-locker
Lock for golang, support monolithic application lock or distributed lock.
https://github.com/x-punch/x-locker
lock mutex mutex-lock redlock sync
Last synced: about 1 month ago
JSON representation
Lock for golang, support monolithic application lock or distributed lock.
- Host: GitHub
- URL: https://github.com/x-punch/x-locker
- Owner: x-punch
- License: apache-2.0
- Created: 2020-05-25T09:32:49.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-10T09:27:31.000Z (over 4 years ago)
- Last Synced: 2024-06-20T02:13:29.219Z (6 months ago)
- Topics: lock, mutex, mutex-lock, redlock, sync
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# X Locker
sync.Mutex can be used to lock in golang, but you need to define the mutex in advance.
Sometimes what we want to lock is generated dynamicly, so this package is used to lock in dynamic.
We can group some lock by id, and they shared the same mutex.## Usage
```go
import locker "github.com/x-punch/x-locker"
```
```go
l := locker.NewLocker()
```
```go
l.Lock("id")
defer l.Unlock("id")
// do something
```# Redlock
Redsync provides a Redis-based distributed mutual exclusion lock implementation for Go as described in [this post](http://redis.io/topics/distlock).## Usage
```go
package mainimport (
"log"
"sync"
"time""github.com/go-redis/redis/v8"
"github.com/x-punch/x-locker/redlock"
)func main() {
locker := redlock.New([]redlock.RedisClient{redis.NewClient(&redis.Options{Addr: ":6379"})})l := locker.NewLock("id")
if err := l.Lock(); err != nil {
panic(err)
}
defer l.Unlock()
// do something
}
```