redislock

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2021 License: MIT Imports: 6 Imported by: 0

README

redis-lock

Build Status Coverage Status License GoDoc

Base on https://redis.io/topics/distlock

Features

  • Support multiple redis instance

Installation

go get -u github.com/teambition/redis-lock

Licenses

All source code is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrGetLockFailed = errors.New("get lock failed")
	ErrGetNewLock    = errors.New("please use Locker to get lock")
	ErrNoRedisClient = errors.New("no redis clients")
	ErrMustBeOdd     = errors.New("the redis count must be odd")
)

Functions

This section is empty.

Types

type Lock

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

Lock ...

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock the lock

type Locker

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

Locker ...

func NewLocker

func NewLocker(clients []redis.Cmdable, opts Options) (*Locker, error)

NewLocker ...

func (*Locker) Lock

func (l *Locker) Lock(key string) (*Lock, error)

Lock lock

func (*Locker) LockWithExpiration added in v0.2.0

func (l *Locker) LockWithExpiration(key string, expiration time.Duration) (*Lock, error)

LockWithExpiration lock

type Options

type Options struct {
	KeyPrefix string
	// The maximum duration to lock a key, Default: 10s
	LockTimeout time.Duration
	// The maximum duration to wait to get the lock, Default: 0s, do not wait
	WaitTimeout time.Duration
	// The maximum wait retry time to get the lock again, Default: 100ms
	WaitRetry time.Duration
}

Options ...

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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