dlock

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 5 Imported by: 0

README

DLock GoDoc

Distributed lock using redis

Import
import "github.com/4vn/dlock"
Usage
l := dlock.New("127.0.0.1:6379")
if lockId, err := l.Lock("user1", 100*time.Millisecond); err != nil {
	log.Println("Lock failed")
}
defer l.Unlock("user1", lockId)

// Do something
License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

func New

func New(addr string) *Lock

New creates Lock object

func (*Lock) Lock

func (l *Lock) Lock(key string, timeout time.Duration) (string, error)

Lock attempts to put a lock on the key for a specified duration. returns error if failed.

func (*Lock) Unlock

func (l *Lock) Unlock(key, id string) error

Unlock attempts to remove the lock on a key if the id matches. returns error if failed.

Jump to

Keyboard shortcuts

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