Documentation ¶
Overview ¶
Package lock 分布式锁实现 分布式锁需要有客户端信息,只可以获得锁的客户端自己解锁或者等待锁自己过期 当未能获得锁需要等待锁释放时可以通过wait接口实现
Index ¶
- Constants
- Variables
- func WithAutoRefreshInterval(autoRefreshInterval string) optparams.Option[Options]
- func WithCheckPeriod(checkperiod time.Duration) optparams.Option[Options]
- func WithClientID(key string) optparams.Option[Options]
- func WithKey(key string) optparams.Option[Options]
- func WithMaxTTL(maxTTL time.Duration) optparams.Option[Options]
- func WithNamespace(ns ...string) optparams.Option[Options]
- func WithSpecifiedKey(key string) optparams.Option[Options]
- func WithTaskCron(taskCron *cron.Cron) optparams.Option[Options]
- type Lock
- type LockInterface
- type Options
Constants ¶
View Source
const MiniCheckPeriod = 100 * time.Microsecond
MiniCheckPeriod 等待的轮询间隔最低100微秒
Variables ¶
View Source
var ErrAlreadyLocked = errors.New("already locked")
ErrAlreadyLocked 该锁已经被锁定
View Source
var ErrAlreadyUnLocked = errors.New("already unlocked")
ErrAlreadyUnLocked 该锁已经被解锁
View Source
var ErrCheckPeriodLessThan100Microsecond = errors.New("checkperiod less than 100 microsecond")
ErrCheckPeriodLessThan100Microsecond checkperiod小于100微秒
View Source
var ErrNoRightToUnLock = errors.New("no right to unlock")
ErrNoRightToUnLock 无权解锁该锁
Functions ¶
func WithAutoRefreshInterval ¶ added in v2.0.1
WithAutoRefreshInterval 设置自动刷新过期时间的设置
func WithCheckPeriod ¶ added in v2.0.1
WithCheckPeriod 锁的设置项,设置检查锁状态的轮询间隔时间
func WithClientID ¶ added in v2.0.1
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithMaxTTL ¶ added in v2.0.1
WithMaxTTL 设置token消减间隔时长,单位s
func WithNamespace ¶ added in v2.0.1
WithNamespace 中间件通用设置,指定锁的命名空间
func WithSpecifiedKey ¶ added in v2.0.1
WithSpecifiedKey 中间件通用设置,指定使用的键,注意设置key后namespace将失效
func WithTaskCron ¶ added in v2.0.1
WithTaskCron 设置定时器
Types ¶
type Lock ¶
type Lock struct { *middlewarehelper.MiddleWareAbc *clientIdhelper.ClientIDAbc // contains filtered or unexported fields }
Lock 分布式锁结构
Click to show internal directories.
Click to hide internal directories.