https://github.com/vanng822/gorlock
Redis Lock wrapper for running distributed tasks
https://github.com/vanng822/gorlock
go redis-lock
Last synced: 2 months ago
JSON representation
Redis Lock wrapper for running distributed tasks
- Host: GitHub
- URL: https://github.com/vanng822/gorlock
- Owner: vanng822
- License: mit
- Created: 2016-08-10T22:55:23.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2025-12-15T20:06:45.000Z (6 months ago)
- Last Synced: 2025-12-25T22:30:43.463Z (6 months ago)
- Topics: go, redis-lock
- Language: Go
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gorlock
Redis Lock wrapper for running distributed tasks. You can customize settings or configure and manage own redis client.
# Usage
```go
import (
"fmt"
"github.com/vanng822/gorlock"
)
// using default instance
gorlock.Run("somekey", func() error {
fmt.Println("Doing some job")
return nil
})
```
Or
```go
import (
"fmt"
"github.com/vanng822/gorlock"
)
// using default instance with LockWaiting=true
gorlock.RunWaiting("somekey", func() error {
fmt.Println("Doing some job")
return nil
})
```
Or
```go
import (
"fmt"
"github.com/vanng822/gorlock"
)
// setting up own config/settings
redisConfig := gorlock.RedisConfig{
Address: "localhost:6379",
Database: 0,
ConnectTimeout: 3 * time.Second,
}
waitingSettings := gorlock.Settings{
KeyPrefix: "gorlock",
LockTimeout: 10 * time.Second,
LockWaiting: true,
RetryTimeout: 3 * time.Second,
RetryInterval: 100 * time.Millisecond,
}
lock := gorlock.New(&waitingSettings, &redisConfig)
// Wait for the lock if it is already locked due to LockWaiting=true
lock.Run("somekey", func() error {
fmt.Println("Doing some job")
return nil
})
```