mutex

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

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

func NewMutex

func NewMutex(client redis.UniversalClient, key string, options ...Option) *Mutex

NewMutex Creates a new Mutex with the provided options.

func (*Mutex) Lock

func (m *Mutex) Lock(ctx context.Context) error

Lock blocks until the lock can be acquired. The function intelligently waits for either the lease duration to expire or a pub sub notification that the lock has been released before attempting to acquire the lock.

func (*Mutex) TryLock

func (m *Mutex) TryLock(ctx context.Context) (bool, error)

TryLock attempts to acquire the lock but does not block. Returns whether the lock was acquired.

func (*Mutex) Unlock

func (m *Mutex) Unlock(ctx context.Context) error

Unlock releases the lock. It will also publish an unlock notification on the Redis pub sub channel.

type Option

type Option func(*Options)

func WithClock

func WithClock(clock clock.Clock) Option

WithClock allows a pluggable clock primarily for unit testing.

func WithLeaseDuration

func WithLeaseDuration(leaseDuration time.Duration) Option

WithLeaseDuration specifies the TTL on the underlying Redis map entry. Practically speaking, this is the upper bound on how long a lock will appear to be held when its owner abandons it.

func WithLogger

func WithLogger(logger logr.Logger) Option

WithLogger allows a pluggable logger implementation.

type Options

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

Jump to

Keyboard shortcuts

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