lock

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLockFailed = errors.New("lock failed")

ErrLockFailed 锁失败

View Source
var ErrLocked = errors.New("locked by another session")

ErrLocked 锁已被其他人持有

View Source
var ErrLockerClosed = errors.New("locker has closed")

ErrLockerClosed 锁已被关闭

View Source
var ErrSessionExpired = errors.New("session is expired")

ErrSessionExpired 锁会话过期

Functions

func GetRemoteLockState

func GetRemoteLockState(ctx context.Context, client *clientv3.Client, lockName string) (bool, int64, error)

GetRemoteLockState 获取远程锁的状态

Types

type Locker

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

Locker 分布式锁

func NewLocker

func NewLocker(c *clientv3.Client, owner string, lock string, ttl int) *Locker

NewLocker 新建分布式锁实例

func (*Locker) Close

func (l *Locker) Close()

Close 关闭释放锁,不可再用

func (*Locker) GetLockID

func (l *Locker) GetLockID() string

GetLockID 获取锁的ID

func (*Locker) GetLockRev

func (l *Locker) GetLockRev() int64

GetLockRev 获取锁的版本号

func (*Locker) Lock

func (l *Locker) Lock(ctx context.Context) error

Lock 上锁

func (*Locker) Unlock

func (l *Locker) Unlock(ctx context.Context) error

Unlock 解锁,可继续Lock

Jump to

Keyboard shortcuts

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