redis lock
This commit is contained in:
parent
ec15531eac
commit
44ca97b7d0
|
|
@ -2,6 +2,7 @@ package lock
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"github.com/redis/go-redis/v9"
|
"github.com/redis/go-redis/v9"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -21,7 +22,7 @@ func (c *Mutex) Lock(ctx context.Context, resource string, callback func(ctx con
|
||||||
l := c.locker.GetLock(resource)
|
l := c.locker.GetLock(resource)
|
||||||
|
|
||||||
if err := l.Lock(ctx); err != nil {
|
if err := l.Lock(ctx); err != nil {
|
||||||
return err
|
return fmt.Errorf("lock failed: %w", err)
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
_ = l.Unlock(ctx)
|
_ = l.Unlock(ctx)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue