lock

package module
v0.0.0-...-50d9bff Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

README

redis-lock

redis锁

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RedisClient

type RedisClient struct {
	*redis.Client //redis客户端
	// contains filtered or unexported fields
}

func NewRedisClient

func NewRedisClient(ctx context.Context, client *redis.Client) *RedisClient

*

  • @Description: 初始化redis客户端
  • @param ctx
  • @param client
  • @return *RedisClient

func (*RedisClient) GetLock

func (r *RedisClient) GetLock(key string) *RedisLock

*

  • @Description: 获取普通锁
  • @receiver r
  • @param key 锁
  • @return *RedisLock

func (*RedisClient) WatchDog

func (r *RedisClient) WatchDog(unlockCh chan struct{}, key string, random uuid.UUID, renewSec int64)

*

  • @Description: 锁续约
  • @receiver r
  • @param unlockCh 解锁通知通道
  • @param key 锁key
  • @param random 锁值
  • @param renewSec 锁续约时长

type RedisLock

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

func (*RedisLock) Lock

func (l *RedisLock) Lock(block bool, expire time.Duration) (bool, error)

*

  • @Description: 上锁
  • @receiver l
  • @param block 是否阻塞获取
  • @param expire 锁过期时间(设置0永不过期)
  • @return bool
  • @return error

func (*RedisLock) LockWaitSeconds

func (l *RedisLock) LockWaitSeconds(waitSeconds int64, expire time.Duration) (bool, error)

*

  • @Description: 限时上锁
  • @receiver l
  • @param waitSeconds 等待时长秒
  • @param expireTime 锁过期时长
  • @return bool
  • @return error

func (*RedisLock) Renew

func (l *RedisLock) Renew(renewSec int64) *RedisLock

*

  • @Description: 设置续约时长
  • @receiver l
  • @param renewSec

func (*RedisLock) Unlock

func (l *RedisLock) Unlock()

*

  • @Description: 解锁
  • @receiver l

Jump to

Keyboard shortcuts

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