locks

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Locker

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

Locker is a lock implementation where grabbing returns a lock value and that value must be used to release or extend the lock.

func NewLocker

func NewLocker(key string, expiration time.Duration) *Locker

NewLocker creates a new locker using the given key and expiration

func (*Locker) Extend

func (l *Locker) Extend(ctx context.Context, vp *valkey.Pool, value string, expiration time.Duration) error

Extend extends our lock expiration by the passed in number of seconds provided the lock value is correct

func (*Locker) Grab

func (l *Locker) Grab(ctx context.Context, vp *valkey.Pool, retry time.Duration) (string, error)

Grab tries to grab this lock in an atomic operation. It returns the lock value if successful. It will retry every second until the retry period has ended, returning empty string if not acquired in that time.

func (*Locker) IsLocked

func (l *Locker) IsLocked(ctx context.Context, vp *valkey.Pool) (bool, error)

IsLocked returns whether this lock is currently held by any process.

func (*Locker) Release

func (l *Locker) Release(ctx context.Context, vp *valkey.Pool, value string) error

Release releases this lock if the given lock value is correct (i.e we own this lock). It is not an error to release a lock that is no longer present.

Jump to

Keyboard shortcuts

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