locker

package
v0.0.0-...-58998d9 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultExpiry = 1 * time.Second

DefaultExpiry signifies the default expiration for an acquired lock

Variables

View Source
var (
	// ErrNotObtained is returned when a lock cannot be obtained.
	ErrNotObtained = redislock.ErrNotObtained

	// ErrNotHeld is returned when trying to release an inactive lock.
	ErrNotHeld = redislock.ErrLockNotHeld
)

Functions

This section is empty.

Types

type Locker

type Locker interface {
	Lock(context.Context, string, ...Option) (Unlocker, error)
}

Locker creates a distributed lock provided a uniquely identifiable lock key

type Option

type Option func(*config)

Option for overriding the default locking settings

func WithTTL

func WithTTL(ttl time.Duration) Option

WithTTL allows one to set a time to live for the mutex lock

type RedisLocker

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

RedisLocker implements the Locker interface for Redis

func NewRedisLocker

func NewRedisLocker(c redislock.RedisClient) *RedisLocker

NewRedisLocker creates a Locker implementation for Redis

func (*RedisLocker) Lock

func (l *RedisLocker) Lock(ctx context.Context, key string, opts ...Option) (Unlocker, error)

Lock attempts to acquire a lock on a specific Redis key and sets expiry if acquired in case release is not triggered

type RedisUnlocker

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

RedisUnlocker implements the Unlocker interface for Redis

func (*RedisUnlocker) Unlock

func (r *RedisUnlocker) Unlock() error

Unlock releases a Redis mutex

type Unlocker

type Unlocker interface {
	Unlock() error
}

Unlocker releases the mutex lock

Jump to

Keyboard shortcuts

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