File tree Expand file tree Collapse file tree 2 files changed +9
-1
lines changed
Expand file tree Collapse file tree 2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,10 @@ func WithRedsyncOptions(options ...redsync.Option) LockerOption {
2222 locker .options = options
2323 }
2424}
25+
26+ // WithKeyPrefix is a LockerOption for adding a prefix to the lock key
27+ func WithKeyPrefix (prefix string ) LockerOption {
28+ return func (locker * redisLocker ) {
29+ locker .keyPrefix = prefix
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -75,10 +75,11 @@ type redisLocker struct {
7575 rs * redsync.Redsync
7676 options []redsync.Option
7777 autoExtendDuration time.Duration
78+ keyPrefix string
7879}
7980
8081func (r * redisLocker ) Lock (ctx context.Context , key string ) (gocron.Lock , error ) {
81- mu := r .rs .NewMutex (key , r .options ... )
82+ mu := r .rs .NewMutex (r . keyPrefix + key , r .options ... )
8283 err := mu .LockContext (ctx )
8384 if err != nil {
8485 return nil , ErrFailedToObtainLock
You can’t perform that action at this time.
0 commit comments