Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRedsyncLockManager ¶
func NewRedsyncLockManager(redisClient redis.UniversalClient, opts ...Option) lockmanager.LockManager
NewRedsyncLockManager constructs a new distributed LockManager using go-redis as backend. Optional configuration such as custom token generator and default mutex options can be provided.
Example usage:
locker := redsync.NewRedsyncLockManager(
redisClient,
redsync.WithTokenGenerator(func(key string) string {
return "custom-token-for:" + key
}),
redsync.WithRedsyncOptions(
redsync.WithTries(10),
redsync.WithRetryDelay(100*time.Millisecond),
),
)
token, err := locker.Acquire(ctx, "resource-key", 5*time.Second)
if err != nil {
log.Fatalf("failed to acquire lock: %v", err)
}
defer locker.Release(ctx, "resource-key", token)
Types ¶
type Option ¶
type Option func(*redsyncLockManager)
Option represents a functional option for configuring redsyncLockManager.
func WithRedsyncOptions ¶
WithRedsyncOptions sets default options for all mutexes created by this LockManager. These options apply to both Acquire and Release calls.
func WithTokenGenerator ¶
WithTokenGenerator sets a custom function for generating lock tokens based on the lock key. If not provided, a default XID-based generator will be used.
Click to show internal directories.
Click to hide internal directories.