redislock

package
v1.12.22 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultExpire = 10 // 加锁的key默认过期时间,单位s

Functions

This section is empty.

Types

type Lock

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

Lock lock data.

func New

func New(conn redis.Conn, key string, val interface{}, expire int) *Lock

New 实例化redis分布式锁实例对象

func (*Lock) TryLock

func (lock *Lock) TryLock() (bool, error)

TryLock 尝试加锁,如果加锁成功就返回true,nil 利用redis setEx nx的原子性实现分布式锁

func (*Lock) Unlock

func (lock *Lock) Unlock() error

Unlock 释放锁采用redis lua脚步执行,成功返回nil

Jump to

Keyboard shortcuts

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