https://github.com/vvanglro/gredlock
🔒 The golang implemetation of Redis distributed locks
https://github.com/vvanglro/gredlock
go go-redis-lock redis-go redislock redlock
Last synced: 5 months ago
JSON representation
🔒 The golang implemetation of Redis distributed locks
- Host: GitHub
- URL: https://github.com/vvanglro/gredlock
- Owner: vvanglro
- Created: 2022-05-26T07:08:17.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-11-07T09:44:46.000Z (over 3 years ago)
- Last Synced: 2025-08-23T01:31:03.731Z (10 months ago)
- Topics: go, go-redis-lock, redis-go, redislock, redlock
- Language: Go
- Homepage:
- Size: 14.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## gredlock
The golang redlock algorithm implementation.
## Installation
```shell
go get -u github.com/vvanglro/gredlock@v0.1.3
```
## Quickstart
```go
package main
import (
"context"
"fmt"
red "github.com/go-redis/redis/v8"
"github.com/vvanglro/gredlock/redlock"
)
func main() {
ctx := context.Background()
options := []*red.Options{
{
Network: "tcp",
Addr: "localhost:56379",
},
{
Network: "tcp",
Addr: "localhost:56378",
},
}
locker := redlock.NewRedisLock(ctx, options...)
lock, err := locker.SetLock(ctx, "my-key", "123", 50)
fmt.Println(lock)
fmt.Println(err)
ttl, err := locker.GetLockTtl(ctx, "my-key", "123")
fmt.Println(ttl)
fmt.Println(err)
isLock := locker.IsLocked(ctx, "my-key")
fmt.Println(isLock)
unlock, err := locker.UnSetLock(ctx, "my-key", "123")
fmt.Println(unlock)
fmt.Println(err)
}
```
## Developing
### Running Tests
```bash
# Start the Redis Containers
docker-compose up -d
# Run Tests
go test ./...
# Stop the Containers
docker-compose down
```