Documentation
¶
Index ¶
Constants ¶
View Source
const LockOwnerKey contextKey = "lock_owner"
Variables ¶
View Source
var ( ErrLockAcquisitionTimeout = errors.New("lock acquisition timed out") ErrLockNotHeld = errors.New("lock not held") )
Functions ¶
This section is empty.
Types ¶
type InMemLocker ¶
type InMemLocker struct {
// contains filtered or unexported fields
}
InMemLocker is a simple thread-safe in-memory locker.
func (*InMemLocker) Close ¶
func (l *InMemLocker) Close() error
type Locker ¶
type Locker interface {
// Acquire attempts to acquire a lock for the given key.
// ttl is the maximum time the lock can be held before auto-expiring.
// timeout is the maximum time to wait for the lock to become available.
Acquire(ctx context.Context, key string, ttl time.Duration, timeout time.Duration) (bool, error)
// Release releases the lock for the given key.
Release(ctx context.Context, key string) error
// Close shuts down the locker.
Close() error
}
Locker defines the interface for distributed locking.
type NATSLocker ¶
type NATSLocker struct {
// contains filtered or unexported fields
}
NATSLocker implements Locker using NATS JetStream KeyValue.
func NewNATSLocker ¶
NewNATSLocker creates a new NATSLocker.
func (*NATSLocker) Close ¶
func (l *NATSLocker) Close() error
type RedisLocker ¶
type RedisLocker struct {
// contains filtered or unexported fields
}
RedisLocker implements Locker using Redis.
func NewRedisLocker ¶
func NewRedisLocker(client *redis.Client) *RedisLocker
NewRedisLocker creates a new RedisLocker.
func (*RedisLocker) Close ¶
func (l *RedisLocker) Close() error
Click to show internal directories.
Click to hide internal directories.