Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type InMemoryLocker ¶ added in v0.5.0
type InMemoryLocker struct {
// contains filtered or unexported fields
}
InMemoryLocker implements Locker using in-process mutexes.
func NewInMemoryLocker ¶ added in v0.5.0
func NewInMemoryLocker() *InMemoryLocker
NewInMemoryLocker creates a new in-process Locker.
type Locker ¶
type Locker interface {
// Acquire blocks until the lock for key is obtained or the context is cancelled.
// If ttl is greater than zero, the lock is automatically released after the duration.
Acquire(ctx context.Context, key string, ttl time.Duration) error
// TryLock attempts to obtain the lock without waiting. It returns true on success.
TryLock(ctx context.Context, key string, ttl time.Duration) (bool, error)
// Release frees the lock for the given key.
Release(ctx context.Context, key string) error
}
Locker defines the interface for distributed or local locks.
Example:
// Assuming a RedisLocker implementation locker := NewRedisLocker(redisClient) locker.Acquire(ctx, "my-resource", 5*time.Second)
Click to show internal directories.
Click to hide internal directories.