Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,9 @@ func WithRedsyncOptions(options ...redsync.Option) LockerOption {
locker.options = options
}
}

func WithKeyPrefix(prefix string) LockerOption {
return func(locker *redisLocker) {
locker.keyPrefix = prefix
}
}
3 changes: 2 additions & 1 deletion redislock.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ type redisLocker struct {
rs *redsync.Redsync
options []redsync.Option
autoExtendDuration time.Duration
keyPrefix string
}

func (r *redisLocker) Lock(ctx context.Context, key string) (gocron.Lock, error) {
mu := r.rs.NewMutex(key, r.options...)
mu := r.rs.NewMutex(r.keyPrefix+key, r.options...)
err := mu.LockContext(ctx)
if err != nil {
return nil, ErrFailedToObtainLock
Expand Down
Loading