Skip to content

๐Ÿ”’ The golang implemetation of Redis distributed locks

Notifications You must be signed in to change notification settings

vvanglro/gredlock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

gredlock

The golang redlock algorithm implementation.

Installation

go get -u github.com/vvanglro/gredlock@v0.1.3

Quickstart

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

# Start the Redis Containers
docker-compose up -d

# Run Tests
go test ./...

# Stop the Containers
docker-compose down

About

๐Ÿ”’ The golang implemetation of Redis distributed locks

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages