redis

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultLeaseTTL is the default TTL for a lease.
	DefaultLeaseTTL = 30 * time.Second
	// RedisLeasePrefix is a prefix used for Redis keys.
	RedisLeasePrefix = "warden:lease:"
)

Variables

View Source
var ErrConflict = errors.New("lease is held by another owner")

ErrConflict is returned when the lease is held by another owner or doesn't exist.

Functions

This section is empty.

Types

type Lease

type Lease struct {
	// Key is the lease identifier.
	Key string
	// FencingToken is a unique token used to prevent conflicts when releasing or renewing the lease.
	FencingToken string
	// TTL is the time-to-live duration for the lease.
	TTL time.Duration
	// contains filtered or unexported fields
}

Lease represents a distributed lease on a key. A Lease is safe for concurrent use by multiple goroutines.

func (*Lease) Expiry

func (l *Lease) Expiry(ctx context.Context) (time.Duration, error)

Expiry returns the remaining TTL of the lease.

func (*Lease) Lock

func (l *Lease) Lock(ctx context.Context) error

Lock acquires the lease, blocking until the lock is available or the context is canceled.

func (*Lease) Renew

func (l *Lease) Renew(ctx context.Context) error

Renew renews the lease by extending the TTL. Returns ErrConflict if the lease is not held by this fencing token.

func (*Lease) TryLock

func (l *Lease) TryLock(ctx context.Context) error

TryLock attempts to acquire the lease without blocking. Returns ErrConflict if the lease is held by another owner.

func (*Lease) Unlock

func (l *Lease) Unlock(ctx context.Context) error

Unlock releases the lease. Returns ErrConflict if the lease is not held by this fencing token.

type Manager

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

Manager manages distributed leases.

func NewManager

func NewManager(rds redis.UniversalClient) *Manager

NewManager creates a new Manager with the given Redis client.

func (*Manager) Lease

func (m *Manager) Lease(key string) *Lease

Lease creates a new Lease for the given key with the default configuration. The lease is not acquired until [Lock] or [TryLock] is called on it.

Jump to

Keyboard shortcuts

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