sync

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTryLockTimeout = errors.New("尝试获取锁超时")
	ErrLockOccurred   = errors.New("锁已经被占用")
	ErrLockNotExists  = errors.New("锁不存在")
)

Functions

This section is empty.

Types

type LockOption

type LockOption func(*LockOptions)

func WithLockTimeout

func WithLockTimeout(timeout time.Duration) LockOption

WithLockTimeout 设置超时时间

type LockOptions

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

type Locker

type Locker interface {
	// TryLock 尝试获取锁,不会阻塞
	TryLock(opts ...LockOption) error
	// Lock 加锁,未获取到锁时会阻塞,可以设置一个超时时长
	Lock(opts ...LockOption) error
	// Unlock 解锁
	Unlock() error
	// TryLockKey 根据某个key去尝试获取锁
	TryLockKey(key string, opts ...LockOption) error
	// LockKey 根据某个key去进行加锁
	LockKey(key string, opts ...LockOption) error
	// UnlockKey 根据某个key去解锁
	UnlockKey(key string) error
}

Locker 分布式锁接口,默认使用redis

func NewLocker

func NewLocker(keyPrefix string) Locker

NewLocker 新建一个锁对象

Jump to

Keyboard shortcuts

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