Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultExpiration redis锁默认过期时间 DefaultExpiration = 5 * time.Second // DefaultRetryDelayTimes 每次重新获取锁的默认间隔时间 DefaultRetryDelayTimes = 100 * time.Millisecond )
View Source
const ( // RedisLockKeyPrefix redis锁的前缀 RedisLockKeyPrefix = "REDIS_LOCK_PREFIX_" // RedisLockDefaultValue redis锁默认值 RedisLockDefaultValue = "1" )
View Source
const (
NativeDefaultValue = "native"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DistributedLock ¶
type DistributedLock interface {
// TryLock 尝试获得锁
// key : 锁的key
// expireTime : 锁的过期时间
// waitTime : 等待获取锁的超时时间
TryLock(ctx context.Context, key string, expireTime, waitTime time.Duration) (bool, error)
// UnLock 释放锁
UnLock(ctx context.Context, key string) (bool, error)
// RefreshLock 更新锁,存在则更新过期时间,不存在则创建key
RefreshLock(ctx context.Context, key string, expireTime time.Duration) (bool, error)
}
type NativeLock ¶
type NativeLock struct {
// contains filtered or unexported fields
}
NativeLock 本地的锁,理论来说,这个锁只能按照指定的key锁住本机器上的功能,且没有自动的过期时间,需要手动释放
func NewNativeLock ¶
func NewNativeLock() *NativeLock
func (*NativeLock) RefreshLock ¶
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
func NewRedisLock ¶
func (*RedisLock) RefreshLock ¶
Click to show internal directories.
Click to hide internal directories.