redlock-go

module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2019 License: MIT

README

RedLock-go

Go Report Card Build Status Coverage Status

Redis distributed locks in Golang

This Golang lib implements the Redis-based distributed lock manager algorithm described in this blog post.

Usage

To create a lock manager:

lockMgr, err := redlock.NewRedLock([]string{
        "tcp://127.0.0.1:6379",
        "tcp://127.0.0.1:6380",
        "tcp://127.0.0.1:6381",
})

To acquire a lock:

expirity, err := lockMgr.Lock("resource_name", 200)

Where the resource name is an unique identifier of what you are trying to lock and 200 is the number of milliseconds for the validity time.

The err is not nil if the lock was not acquired (you may try again), otherwise an expirity lager than zero is returned representing the number of milliseconds the lock will be valid.

To release a lock:

err := lockMgr.UnLock()

You can find sample code in _examples dir.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL