lock

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLockerClosed           = errors.New("locker has closed")
	ErrLocked                 = errors.New("locked by another session")
	ErrSessionExpired         = errors.New("session is expired")
	ErrLockFailed             = errors.New("lock failed")
	ErrLockRemoteNoneNeedTodo = errors.New("remote lock is none, can try to grab")
)

Functions

func CreateLease

func CreateLease(ctx context.Context, client *clientv3.Client, leaseTTL int64) (*clientv3.LeaseGrantResponse, clientv3.LeaseID, error)

func GetFirstCrt

func GetFirstCrt(ctx context.Context, client *clientv3.Client, key string) (*clientv3.GetResponse, map[string]string, error)

func GetRemoteLockState

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

GetRemoteLockState 获取远程锁的状态

func PutWithLease

func PutWithLease(ctx context.Context, client *clientv3.Client, key string, value string, leaseID clientv3.LeaseID) (*clientv3.PutResponse, error)

Types

type Locker

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

func NewLocker

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

NewLocker Create a new distributed lock instance, note that if it is no longer used, please call Close.

func (*Locker) Close

func (l *Locker) Close()

Close Close lock, no longer available

func (*Locker) GetLockID

func (l *Locker) GetLockID() string

func (*Locker) GetLockRev

func (l *Locker) GetLockRev() int64

func (*Locker) Lock

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

func (*Locker) Unlock

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

Unlock Unlock, continue to Lock

Jump to

Keyboard shortcuts

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