Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrLockAcquireFailed = errors.New("failed to acquire lock") // lock acquisition failed. ErrLockReleaseUnlocked = errors.New("cannot release an unlocked lock") // release a lock that doesn't exist. ErrLockReleaseForbidden = errors.New("cannot release a lock that's no longer owned") // release a lock owned by someone else. )
Sentinel errors for lock operations.
Functions ¶
func ReleaseLock ¶
ReleaseLock releases a distributed lock using a Lua script for atomic operation. The Lua script ensures that only the lock owner (matching token) can release it.
Types ¶
type LockData ¶
LockData represents a distributed lock.
func AcquireLock ¶
func AcquireLock( ctx context.Context, redisClient *redis.Client, key string, timeout time.Duration, interval time.Duration, wait bool, waitTimeout time.Duration, ) *LockData
AcquireLock attempts to acquire a distributed lock. It uses SETNX (SET if Not eXists) with expiration to create the lock. If wait is true, it will retry at the specified interval until waitTimeout.
func AcquireMultipleLock ¶
func AcquireMultipleLock( ctx context.Context, redisClient *redis.Client, keys []string, timeout time.Duration, interval time.Duration, wait bool, waitTimeout time.Duration, ) ([]*LockData, error)
AcquireMultipleLock attempts to acquire multiple locks atomically. It uses a pipeline to batch SETNX operations.
Click to show internal directories.
Click to hide internal directories.