Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrLockStopped 锁已停止错误 ErrLockStopped = errors.New("锁已停止") // ErrLockNotAcquired 锁未获取错误 ErrLockNotAcquired = errors.New("锁未获取") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// 锁名称
LockName string
// 锁过期时间
Expiry time.Duration
// 锁重试间隔时间
RetryDelay time.Duration
// 获取锁最大重试次数
MaxRetries int
// 续约间隔时间(默认过期时间的1/3)
RenewalInterval time.Duration
// 状态通道缓冲区大小
StatusChanBuffer int
}
Config 锁配置
type LockRedsync ¶
type LockRedsync struct {
// contains filtered or unexported fields
}
LockRedsync 分布式锁重构版
func NewLockRedsync ¶
NewLockRedsync 创建分布式锁
func (*LockRedsync) CreateMutex ¶
func (dl *LockRedsync) CreateMutex(name string) *redsync.Mutex
CreateMutex 创建一个新的 mutex 实例
func (*LockRedsync) GetLockInfo ¶
func (dl *LockRedsync) GetLockInfo() map[string]interface{}
GetLockInfo 获取锁信息
func (*LockRedsync) Start ¶
func (dl *LockRedsync) Start() <-chan LockResult
Start 启动锁服务 返回状态通道,用于接收锁状态变更通知
type LockStatus ¶
type LockStatus int
LockStatus 锁状态枚举
const ( // LockStatusUnknown 锁未知状态 LockStatusUnknown LockStatus = iota // LockStatusAcquired 锁已获取 LockStatusAcquired // LockStatusLost 锁丢失 LockStatusLost // LockStatusReleased 锁释放 LockStatusReleased )
type RedSyncIn ¶
type RedSyncIn interface {
Start() <-chan LockResult
Stop()
IsLocked() bool
Status() LockStatus
GetLockInfo() map[string]interface{}
CreateMutex(name string) *redsync.Mutex
}
Click to show internal directories.
Click to hide internal directories.