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) Lock ¶
Lock acquires the lease, blocking until the lock is available or the context is canceled.
func (*Lease) Renew ¶
Renew renews the lease by extending the TTL. Returns ErrConflict if the lease is not held by this fencing token.
func (*Lease) TryLock ¶
TryLock attempts to acquire the lease without blocking. Returns ErrConflict if the lease is held by another owner.
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.
Click to show internal directories.
Click to hide internal directories.