From 03df4bec8313549cac638ac6a4081b446aa2c080 Mon Sep 17 00:00:00 2001 From: "Pavel @grbit Griaznov" Date: Thu, 18 Jan 2024 16:08:52 +0100 Subject: [PATCH] Add redsync Mutex options for LockRedis and use context in LockRedis --- locks.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/locks.go b/locks.go index c9c72fb..70117bc 100644 --- a/locks.go +++ b/locks.go @@ -124,21 +124,21 @@ type LockRedis struct { } // NewLockRedis creates a new instance of LockRedis. -func NewLockRedis(pool redsyncredis.Pool, mutexName string) *LockRedis { +func NewLockRedis(pool redsyncredis.Pool, mutexName string, oo ...redsync.Option) *LockRedis { rs := redsync.New(pool) - mutex := rs.NewMutex(mutexName) + mutex := rs.NewMutex(mutexName, oo...) return &LockRedis{mutex: mutex} } // Lock locks the lock in Redis. -func (l *LockRedis) Lock(_ context.Context) error { - err := l.mutex.Lock() +func (l *LockRedis) Lock(ctx context.Context) error { + err := l.mutex.LockContext(ctx) return errors.Wrap(err, "failed to lock a mutex in redis") } // Unlock unlocks the lock in Redis. -func (l *LockRedis) Unlock(_ context.Context) error { - if ok, err := l.mutex.Unlock(); !ok || err != nil { +func (l *LockRedis) Unlock(ctx context.Context) error { + if ok, err := l.mutex.UnlockContext(ctx); !ok || err != nil { return errors.Wrap(err, "failed to unlock a mutex in redis") } return nil