lock

package
v0.0.0-...-f5ed4d4 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: AGPL-3.0 Imports: 10 Imported by: 2 modules, 7 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (

	// LockTimeout is the expiration of a redis lock if any operation is longer
	// than this, it should refresh the lock.
	LockTimeout = 20 * time.Second

	// WaitTimeout is the maximum time to wait before returning control to caller.
	WaitTimeout = 1 * time.Minute

	// WaitRetry is the time to wait between retries.
	WaitRetry = 100 * time.Millisecond
)

Variables

View Source
var (
	// ErrTooManyRetries is the error returned when despite several tries
	// we never managed to get a lock
	ErrTooManyRetries = errors.New("abort after too many failures without getting the lock")
)

Functions

This section is empty.

Types

type ErrorLocker

type ErrorLocker interface {
	Lock() error
	Unlock()
}

An ErrorLocker is a locker which can fail (returns an error)

type ErrorRWLocker

type ErrorRWLocker interface {
	ErrorLocker
	RLock() error
	RUnlock()
}

ErrorRWLocker is the interface for a RWLock as inspired by RWMutex

type Getter

type Getter interface {
	// ReadWrite returns the read/write lock for the given name.
	// By convention, the name should be prefixed by the instance domain on which
	// it applies, then a slash and the package name (ie alice.example.net/vfs).
	ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker

	// LongOperation returns a lock suitable for long operations. It will refresh
	// the lock in redis to avoid its automatic expiration.
	LongOperation(db prefixer.Prefixer, name string) ErrorLocker
}

Getter returns a lock on a resource matching the given `name`.

func New

func New(client redis.UniversalClient) Getter

type InMemoryLockGetter

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

func NewInMemory

func NewInMemory() *InMemoryLockGetter

func (*InMemoryLockGetter) LongOperation

func (i *InMemoryLockGetter) LongOperation(db prefixer.Prefixer, name string) ErrorLocker

LongOperation returns an in-memory lock, which does not expire.

func (*InMemoryLockGetter) ReadWrite

func (i *InMemoryLockGetter) ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker

type RedisLockGetter

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

func NewRedisLockGetter

func NewRedisLockGetter(client redis.UniversalClient) *RedisLockGetter

func (*RedisLockGetter) LongOperation

func (r *RedisLockGetter) LongOperation(db prefixer.Prefixer, name string) ErrorLocker

LongOperation returns a lock suitable for long operations. It will refresh the lock in redis to avoid its automatic expiration.

func (*RedisLockGetter) ReadWrite

func (r *RedisLockGetter) ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker

Jump to

Keyboard shortcuts

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