Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) 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.