redislock

package
v0.0.0-...-06bcc1c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisLock

type RedisLock struct {
	// contains filtered or unexported fields
}

RedisLock is a redis SET NX based lock

func New

func New(cli redislock.RedisClient, key string, waitTimeout, lockTTL time.Duration) (*RedisLock, error)

New creates a lock key: name of the lock waitTimeout: timeout before getting the lock, Lock returns error if the lock is not acquired after this time lockTTL: ttl of lock, after this time, lock will be released automatically

func (*RedisLock) Lock

func (r *RedisLock) Lock(ctx context.Context) (context.Context, error)

Lock acquires the lock will try waitTimeout time before getting the lock

func (*RedisLock) TryLock

func (r *RedisLock) TryLock(ctx context.Context) (context.Context, error)

TryLock tries to lock returns error if the lock is already acquired by someone else will not retry to get lock

func (*RedisLock) Unlock

func (r *RedisLock) Unlock(ctx context.Context) error

Unlock releases the lock if the lock is not acquired, will return ErrLockNotHeld

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL