Documentation
¶
Overview ¶
简单 string 分布式锁操作
分布式锁资源管理 Redis str
Index ¶
- type ErrHookProgress4RedisLock
- type LocalCache
- func (b *LocalCache) Clear(ctx context.Context, errHonk types.ErrHookProgress)
- func (b *LocalCache) Delete(ctx context.Context, key string) error
- func (b *LocalCache) Destroy(ctx context.Context)
- func (b *LocalCache) Get(ctx context.Context, key string) (any, error)
- func (b *LocalCache) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- type RedisCache
- func (r *RedisCache) Clear(ctx context.Context, errHonk types.ErrHookProgress)
- func (r *RedisCache) Delete(ctx context.Context, key string) error
- func (r *RedisCache) Destroy(ctx context.Context)
- func (r *RedisCache) Get(ctx context.Context, key string) (any, error)
- func (r *RedisCache) GetRedis() (*redis.Cmdable, uint8)
- func (r *RedisCache) HDelete(ctx context.Context, hashName string, key string) error
- func (r *RedisCache) HExpire(ctx context.Context, hashName string, expiration time.Duration) error
- func (r *RedisCache) HGet(ctx context.Context, hashName string, key string) (any, error)
- func (r *RedisCache) HGetAll(ctx context.Context, hashName string) (map[string]string, error)
- func (r *RedisCache) HKeys(ctx context.Context, hashName string) ([]string, error)
- func (r *RedisCache) HLength(ctx context.Context, hashName string) (int64, error)
- func (r *RedisCache) HSet(ctx context.Context, hashName string, key string, value any) error
- func (r *RedisCache) LLength(ctx context.Context, listName string) (int64, error)
- func (r *RedisCache) ListPop(ctx context.Context, listName string) (string, error)
- func (r *RedisCache) ListPush(ctx context.Context, listName string, value ...any) error
- func (r *RedisCache) ListShift(ctx context.Context, listName string) (string, error)
- func (r *RedisCache) ListUnshift(ctx context.Context, listName string, value ...any) error
- func (r *RedisCache) Set(ctx context.Context, key string, value any, expiration time.Duration) error
- type RedisDistributeLockResManager
- type RedisDistributeRenewalAndUnlockResManager
- type RedisDistributedLock
- func (rl *RedisDistributedLock) AutoLock(ctx context.Context, key string, expiration time.Duration, ...) (*RedisDistributedRenewalAndUnlock, error)
- func (rl *RedisDistributedLock) AutoLockWithHook(ctx context.Context, key string, expiration time.Duration, ...)
- func (rl *RedisDistributedLock) AutoSingleFightLock(ctx context.Context, key string, expiration time.Duration, ...) (*RedisDistributedRenewalAndUnlock, error)
- func (rl *RedisDistributedLock) Clear()
- func (rl *RedisDistributedLock) Reset(client redis.Cmdable)
- type RedisDistributedRenewalAndUnlock
- func (rl *RedisDistributedRenewalAndUnlock) AutoRenewal(interval time.Duration, timeout time.Duration) error
- func (l *RedisDistributedRenewalAndUnlock) AutoRenewalWithHook(maxRenewingCnt uint, expiration time.Duration, timeout time.Duration, ...)
- func (rl *RedisDistributedRenewalAndUnlock) Clear()
- func (l *RedisDistributedRenewalAndUnlock) Renewal(ctx context.Context) error
- func (rl *RedisDistributedRenewalAndUnlock) Reset(client redis.Cmdable, key string, value string, expiration time.Duration)
- func (l *RedisDistributedRenewalAndUnlock) UnLock(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrHookProgress4RedisLock ¶
type ErrHookProgress4RedisLock func(item *RedisDistributedRenewalAndUnlock, err error)
type LocalCache ¶
type LocalCache struct {
// contains filtered or unexported fields
}
本地缓存结构体
func NewInstance ¶
func NewInstance(cap uint) *LocalCache
func (*LocalCache) Clear ¶
func (b *LocalCache) Clear(ctx context.Context, errHonk types.ErrHookProgress)
func (*LocalCache) Destroy ¶
func (b *LocalCache) Destroy(ctx context.Context)
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache类
func (*RedisCache) Clear ¶
func (r *RedisCache) Clear(ctx context.Context, errHonk types.ErrHookProgress)
慎用,清除掉此库的所有缓存资源
func (*RedisCache) ListUnshift ¶
type RedisDistributeLockResManager ¶
type RedisDistributeLockResManager struct {
// contains filtered or unexported fields
}
加锁资源 --------------------------------------------------------------------------------------------------------------
func GetInstallRedisDistributeLockResManager ¶
func GetInstallRedisDistributeLockResManager() *RedisDistributeLockResManager
Redis 分布式锁资源管理
func (*RedisDistributeLockResManager) Get ¶
func (r *RedisDistributeLockResManager) Get(client redis.Cmdable) (*RedisDistributedLock, error)
func (*RedisDistributeLockResManager) Put ¶
func (r *RedisDistributeLockResManager) Put(item *RedisDistributedLock) error
type RedisDistributeRenewalAndUnlockResManager ¶
type RedisDistributeRenewalAndUnlockResManager struct {
// contains filtered or unexported fields
}
续约/解锁资源 ----------------------------------------------------------------------------------------------------------
func GetInstallRedisDistributeRenewalAndUnlockResManager ¶
func GetInstallRedisDistributeRenewalAndUnlockResManager() *RedisDistributeRenewalAndUnlockResManager
func (*RedisDistributeRenewalAndUnlockResManager) Get ¶
func (r *RedisDistributeRenewalAndUnlockResManager) Get(client redis.Cmdable, key string, value string, expiration time.Duration) (*RedisDistributedRenewalAndUnlock, error)
func (*RedisDistributeRenewalAndUnlockResManager) Put ¶
func (r *RedisDistributeRenewalAndUnlockResManager) Put(item *RedisDistributedRenewalAndUnlock) error
type RedisDistributedLock ¶
type RedisDistributedLock struct {
// contains filtered or unexported fields
}
分布式锁 str 处理
func (*RedisDistributedLock) AutoLock ¶
func (rl *RedisDistributedLock) AutoLock( ctx context.Context, key string, expiration time.Duration, timeout time.Duration, retry *types.FixIntervalRetry, ) (*RedisDistributedRenewalAndUnlock, error)
阻塞式加锁重试方法
func (*RedisDistributedLock) AutoLockWithHook ¶
func (rl *RedisDistributedLock) AutoLockWithHook( ctx context.Context, key string, expiration time.Duration, timeout time.Duration, retry types.FixIntervalRetry, callback ErrHookProgress4RedisLock, )
可以尝试多次加锁,避免一次锁定失败 API ***************************************************************************************************
func (*RedisDistributedLock) AutoSingleFightLock ¶
func (rl *RedisDistributedLock) AutoSingleFightLock( ctx context.Context, key string, expiration time.Duration, timeout time.Duration, retry *types.FixIntervalRetry, ) (*RedisDistributedRenewalAndUnlock, error)
自动singleflight加锁(非常高并发并且热点集中的极端情况下使用,慎用)
func (*RedisDistributedLock) Clear ¶
func (rl *RedisDistributedLock) Clear()
type RedisDistributedRenewalAndUnlock ¶
type RedisDistributedRenewalAndUnlock struct {
// contains filtered or unexported fields
}
续约和释放锁处理(Redis分布式锁)----------------------------------------------------------------------------------------------
func (*RedisDistributedRenewalAndUnlock) AutoRenewal ¶
func (rl *RedisDistributedRenewalAndUnlock) AutoRenewal( interval time.Duration, timeout time.Duration, ) error
自动续约阻塞版本, 一直续约中知道主动的释放锁
func (*RedisDistributedRenewalAndUnlock) AutoRenewalWithHook ¶
func (l *RedisDistributedRenewalAndUnlock) AutoRenewalWithHook( maxRenewingCnt uint, expiration time.Duration, timeout time.Duration, everyRetry types.FixIntervalRetry, callback types.ErrHookProgress, )
自动续约要进行原子操作: 考虑lua, hook版 maxRenewingCnt 续约的此时 expiration 间隔多长时间开始续约 timeout 超时 everyRetry 每次续约的重试策略 callback 钩子函数
func (*RedisDistributedRenewalAndUnlock) Clear ¶
func (rl *RedisDistributedRenewalAndUnlock) Clear()
func (*RedisDistributedRenewalAndUnlock) Renewal ¶
func (l *RedisDistributedRenewalAndUnlock) Renewal(ctx context.Context) error
续约要进行原子操作: 考虑lua, 只能续约1次