gredis

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TryLock

func TryLock(ctx context.Context, key string, tryLockTime time.Duration, expiration time.Duration, redisCli *redis.Client, lockFunc LockFunc) error

Types

type LockFunc

type LockFunc func(ctx context.Context) error

type RedisLock

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

RedisLock redis实现的分布式锁

func NewRedisLock

func NewRedisLock(key, value string, expiration time.Duration, cli *redis.Client) *RedisLock

func (*RedisLock) Lock

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

Lock 添加分布式锁,expiration过期时间,小于等于0,不过期,需要通过 UnLock方法释放锁

func (*RedisLock) RefreshLock

func (rl *RedisLock) RefreshLock() (bool, error)

RefreshLock 存在则更新过期时间,不存在则创建key

func (*RedisLock) TryLock

func (rl *RedisLock) TryLock(ctx context.Context, waitTime time.Duration) (bool, error)

func (*RedisLock) UnLock

func (rl *RedisLock) UnLock(ctx context.Context) (bool, error)

Jump to

Keyboard shortcuts

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