Documentation
¶
Index ¶
- type DistributedLock
- func (l *DistributedLock) Acquire(ctx context.Context) error
- func (l *DistributedLock) Extend(ctx context.Context) error
- func (l *DistributedLock) IsHeld(ctx context.Context) (bool, error)
- func (l *DistributedLock) Release(ctx context.Context) error
- func (l *DistributedLock) TryAcquire(ctx context.Context) (bool, error)
- func (l *DistributedLock) TryWithLock(ctx context.Context, fn func(ctx context.Context) error) (bool, error)
- func (l *DistributedLock) WithLock(ctx context.Context, fn func(ctx context.Context) error) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistributedLock ¶
type DistributedLock struct {
// contains filtered or unexported fields
}
DistributedLock provides distributed locking using Redis.
func NewDistributedLock ¶
NewDistributedLock creates a new distributed lock.
func (*DistributedLock) Acquire ¶
func (l *DistributedLock) Acquire(ctx context.Context) error
Acquire blocks until the lock is acquired or context is canceled.
func (*DistributedLock) Extend ¶
func (l *DistributedLock) Extend(ctx context.Context) error
Extend extends the lock TTL if we still own it.
func (*DistributedLock) IsHeld ¶
func (l *DistributedLock) IsHeld(ctx context.Context) (bool, error)
IsHeld checks if we currently hold the lock.
func (*DistributedLock) Release ¶
func (l *DistributedLock) Release(ctx context.Context) error
Release releases the lock if we own it Uses Lua script for atomic check-and-delete.
func (*DistributedLock) TryAcquire ¶
func (l *DistributedLock) TryAcquire(ctx context.Context) (bool, error)
TryAcquire attempts to acquire the lock without blocking Returns true if lock was acquired, false otherwise.
func (*DistributedLock) TryWithLock ¶
func (l *DistributedLock) TryWithLock( ctx context.Context, fn func(ctx context.Context) error, ) (bool, error)
TryWithLock executes a function if the lock can be acquired Returns false if lock was not acquired.
Click to show internal directories.
Click to hide internal directories.