Documentation
¶
Index ¶
- type DistributedLock
- type DistributedLockManager
- func (dlm *DistributedLockManager) Close()
- func (dlm *DistributedLockManager) Lock(ctx context.Context, lockName string, opts ...LockOption) (string, error)
- func (dlm *DistributedLockManager) Renew(ctx context.Context, lockName, lockCode string, ttl time.Duration) error
- func (dlm *DistributedLockManager) Unlock(lockName, lockCode string) error
- type LockManagerConfig
- type LockOption
- type WithTTL
- type WithWait
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistributedLock ¶
type DistributedLock struct {
ID int64 `xorm:"pk autoincr"`
Name string `xorm:"varchar(255) notnull unique"`
LockCode string `xorm:"varchar(36) notnull"`
ExpireTime time.Time `xorm:"notnull"`
CreatedAt time.Time `xorm:"created notnull"`
}
锁存储结构
type DistributedLockManager ¶
type DistributedLockManager struct {
// contains filtered or unexported fields
}
分布式锁管理器
func NewDistributedLockManager ¶
func NewDistributedLockManager(config LockManagerConfig) (*DistributedLockManager, error)
创建新的分布式锁管理器
func (*DistributedLockManager) Lock ¶
func (dlm *DistributedLockManager) Lock(ctx context.Context, lockName string, opts ...LockOption) (string, error)
阻塞方式获取锁
func (*DistributedLockManager) Renew ¶
func (dlm *DistributedLockManager) Renew(ctx context.Context, lockName, lockCode string, ttl time.Duration) error
续期锁
func (*DistributedLockManager) Unlock ¶
func (dlm *DistributedLockManager) Unlock(lockName, lockCode string) error
解锁
type LockManagerConfig ¶
type LockManagerConfig struct {
RetryInterval time.Duration // 重试间隔,默认 100ms
DefaultAcquireWait time.Duration // 默认获取锁等待时间,默认 10s
DefaultLockTTL time.Duration // 默认锁生存时间,默认 30s
CleanupInterval time.Duration // 清理间隔,默认 1分钟
MaxAcquireRetries int // 最大重试次数,0表示无限次
CleanupBatchSize int // 批量清理数量,默认 100
}
锁管理器配置
type LockOption ¶
type LockOption interface {
// contains filtered or unexported methods
}
锁选项接口
func WithWaitOption ¶
func WithWaitOption(wait time.Duration) LockOption
Click to show internal directories.
Click to hide internal directories.