lock

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLock          = errors.New("lock error")
	ErrTransFinished = errors.New("transaction finished")
	ErrNoTransaction = errors.New("no transaction")
	ErrCommit        = errors.New("commit error")
)

Functions

This section is empty.

Types

type Lock

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

func New

func New(lockId interface{}, client *rds.Pool) (r *Lock, err error)

func (*Lock) Commit

func (this *Lock) Commit() (err error)

仅开启 transaction 时有效,将锁状态切换为 Finished

func (*Lock) GetLockStatus

func (this *Lock) GetLockStatus() (r LockStatus)

func (*Lock) Lock

func (this *Lock) Lock(aliveSeconds int64) (err error)

加锁,需指定锁有效时间 当开启 transaction 时,将锁状态设置为 Doing

func (*Lock) Release

func (this *Lock) Release() (err error)

主动释放锁

func (*Lock) Transaction

func (this *Lock) Transaction() *Lock

func (*Lock) Wait

func (this *Lock) Wait() (err error)

阻塞业务进程并直到锁状态为 normal 时释放阻塞 当开启 transaction 时,锁状态为 Finished 时抛出错误

func (*Lock) WaitAndLock

func (this *Lock) WaitAndLock(aliveSeconds int64) (err error)

阻塞业务进程并直到加锁成功,需指定锁有效时间

type LockStatus

type LockStatus int
const (
	LockStatusNormal   LockStatus = 0
	LockStatusDoing    LockStatus = 1
	LockStatusFinished LockStatus = 2
)

Jump to

Keyboard shortcuts

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