redislock

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var REDIS_CMD_AUTH = "AUTH"
View Source
var REDIS_CMD_DEL = "DEL"
View Source
var REDIS_CMD_EVAL = "EVAL"
View Source
var REDIS_CMD_EXPIRE = "EXPIRE"
View Source
var REDIS_CMD_GET = "GET"
View Source
var REDIS_CMD_PING = "PING"
View Source
var REDIS_CMD_SET = "SET"
View Source
var REDIS_LOCK_SUCC = "OK"
View Source
var REDIS_SET_EX = "EX" //设置过期时间(单位:秒)
View Source
var REDIS_SET_NX = "NX" //设置key-value当指定key不存在时
View Source
var REDIS_SET_WITH_EXPIRE_TIME = "PX" //设置过期时间(单位:毫秒)
View Source
var REDIS_UNLOCK_SUCC = int64(1)

Functions

This section is empty.

Types

type Locker

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

func (*Locker) Unlock

func (locker *Locker) Unlock() (err error)

* @brief 解锁 * @return err 成功返回nil,失败返回error(失败的情况仅限于redis服务器宕机了或执行脚本出错)

type RedisLock

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

func NewRedisLock

func NewRedisLock() *RedisLock

func (*RedisLock) Open

func (rds *RedisLock) Open(strURL string) (err error)

* @brief 打开Redis连接,初始化连接池 * @param strURL Redis连接URL 有用户名密码 "redis://123456@192.168.1.10:6379" * 没有用户名密码则是 "redis://192.168.1.10:6379" * @return err 成功返回nil,失败返回错误类型

func (*RedisLock) TryLock

func (rds *RedisLock) TryLock(strKey, strValue string, nExpireTime int) (locker *Locker, ok bool)
  • @brief 尝试加锁
  • @param strKey Redis唯一key
  • @param strValue Redis值,用于识别哪个用户加锁
  • @param nExpireTime 锁的过期时间(秒)
  • @return locker 加锁成功后,返回用于解锁的对象 err 成功返回nil,失败返回error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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