lock

package
v0.0.0-...-8d1786a Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 9 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoLockObtained is the error when a lock is unable to be attained
	ErrNoLockObtained = errors.New("unable to obtain lock")
	// ErrDidNotUnlock is the error when an unlock did not occur
	ErrDidNotUnlock = errors.New("did not unlock")
)

Functions

func NewRedisDLockPool

func NewRedisDLockPool(addr string, maxIdle *int, maxActive *int,
	idleTimeout *int) redsync.Pool

NewRedisLockingPool returns a Redis pool for go-redsync

Types

type DLock

type DLock interface {
	// Lock attempts to obtain a lock on the given key. expireMillis sets how long
	// this key should be locked for to prevent deadlocks.
	Lock(key string, expireMillis *int) error

	// Unlock attempts to unlock the given key.
	Unlock(key string) error
}

DLock defines an interface for a distributed lock

type LocalDLock

type LocalDLock struct {
	Tries            *int
	RetryDelayMillis *int
	// contains filtered or unexported fields
}

LocalDLock is an implementation of a distributed lock that is a wrapper about a simple in memory map. NOTE: This *isn't* distributed and should only be used for small single server projects or for testing services that require an DLock implementation.

func NewLocalDLock

func NewLocalDLock() *LocalDLock

func (*LocalDLock) Lock

func (m *LocalDLock) Lock(key string, expireMillis *int) error

func (*LocalDLock) Unlock

func (m *LocalDLock) Unlock(key string) error

Unlock attempts to unlock the given key.

type RedisDLock

type RedisDLock struct {
	MutexTries            *int
	MutexRetryDelayMillis *int
	// contains filtered or unexported fields
}

RedisDLock is an implementation of a distributed lock using Redis. This first version expects a single instance of Redis for locking, which isn't truly "distributed", but will work for our simple setup. Basically a wrapper around https://github.com/go-redsync/redsync that implements the Locking interface

func NewRedisDLock

func NewRedisDLock(pools []redsync.Pool, namespace *string) *RedisDLock

func (*RedisDLock) Lock

func (r *RedisDLock) Lock(key string, expireMillis *int) error

Lock attempts to obtain a lock on the given key. expireMillis sets how long this key should be locked for to prevent deadlocks.

func (*RedisDLock) Unlock

func (r *RedisDLock) Unlock(key string) error

Unlock attempts to unlock the given key.

Jump to

Keyboard shortcuts

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