Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrLockerClosed = errors.New("locker closed")
ErrLockerClosed is returned from the Locker.WithContext when the Locker is closed
View Source
var ErrNotLocked = errors.New("not locked")
ErrNotLocked is returned from the Locker.TryWithContext when it fails
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker interface { // WithContext acquires a distributed valkey lock by name by waiting for it. It may return ErrLockerClosed. WithContext(ctx context.Context, name string) (context.Context, context.CancelFunc, error) // TryWithContext tries to acquire a distributed valkey lock by name without waiting. It may return ErrNotLocked. TryWithContext(ctx context.Context, name string) (context.Context, context.CancelFunc, error) // Client exports the underlying valkey.Client Client() valkey.Client // ForceWithContext takes over a distributed valkey lock by canceling the original holder. It may return ErrNotLocked. ForceWithContext(ctx context.Context, name string) (context.Context, context.CancelFunc, error) // Close closes the underlying valkey.Client Close() }
Locker is the interface of valkeylock
func NewLocker ¶
func NewLocker(option LockerOption) (Locker, error)
NewLocker creates the distributed Locker backed by valkey client side caching
type LockerOption ¶
type LockerOption struct { // ClientBuilder can be used to modify valkey.Client used by Locker ClientBuilder func(option valkey.ClientOption) (valkey.Client, error) // KeyPrefix is the prefix of valkey key for locks. Default value is "valkeylock". KeyPrefix string // ClientOption is passed to valkey.NewClient or LockerOption.ClientBuilder to build a valkey.Client ClientOption valkey.ClientOption // KeyValidity is the validity duration of locks and will be extended periodically by the ExtendInterval. Default value is 5s. KeyValidity time.Duration // ExtendInterval is the interval to extend KeyValidity. Default value is 1s. ExtendInterval time.Duration // TryNextAfter is the timeout duration before trying the next valkey key for locks. Default value is 20ms. TryNextAfter time.Duration // KeyMajority is at least how many valkey keys in a total of KeyMajority*2-1 should be acquired to be a valid lock. // Default value is 2. KeyMajority int32 // NoLoopTracking will use NOLOOP in the CLIENT TRACKING command to avoid unnecessary notifications and thus have better performance. // This can only be enabled if all your valkey nodes >= 7.0.5. (https://github.com/redis/redis/pull/11052) NoLoopTracking bool // Use SET PX instead of SET PXAT when acquiring locks to be compatible with Valkey < 6.2 FallbackSETPX bool }
LockerOption should be passed to NewLocker to construct a Locker
Click to show internal directories.
Click to hide internal directories.