Documentation
¶
Index ¶
- type DistLock
- type LocalLock
- func (l *LocalLock) Lock(ctx context.Context, key string) error
- func (l *LocalLock) TryLock(ctx context.Context, key string) (bool, error)
- func (l *LocalLock) TryLockWithTTL(ctx context.Context, key string, ttl time.Duration) (bool, error)
- func (l *LocalLock) Unlock(ctx context.Context, key string) error
- type Option
- type RedisLock
- func (l *RedisLock) Client() *redis.Client
- func (l *RedisLock) Close() error
- func (l *RedisLock) ExtendLock(ctx context.Context, key string, ttl time.Duration) error
- func (l *RedisLock) ExtendLockWithValue(ctx context.Context, key, value string, ttl time.Duration) (bool, error)
- func (l *RedisLock) Lock(ctx context.Context, key string) error
- func (l *RedisLock) LockWithTTL(ctx context.Context, key string, ttl time.Duration) (bool, string, error)
- func (l *RedisLock) Ping(ctx context.Context) error
- func (l *RedisLock) TryLock(ctx context.Context, key string) (bool, error)
- func (l *RedisLock) TryLockWithTTL(ctx context.Context, key string, ttl time.Duration) (bool, error)
- func (l *RedisLock) Unlock(ctx context.Context, key string) error
- func (l *RedisLock) UnlockWithValue(ctx context.Context, key, value string) error
- type RedisPoolOptions
- type Semaphore
- func (s *Semaphore) Acquire(ctx context.Context, identifier string) (bool, error)
- func (s *Semaphore) Cleanup(ctx context.Context, olderThan time.Duration) error
- func (s *Semaphore) Release(ctx context.Context, identifier string) error
- func (s *Semaphore) Renew(ctx context.Context, identifier string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LocalLock ¶
type LocalLock struct {
// contains filtered or unexported fields
}
func NewLocalLock ¶
func NewLocalLock() *LocalLock
func (*LocalLock) TryLockWithTTL ¶
type RedisLock ¶
type RedisLock struct {
// contains filtered or unexported fields
}
func (*RedisLock) ExtendLock ¶
ExtendLock 续期:从 lockValues 取出持有值,用 Lua 脚本安全续期。 若 lockValues 中无记录(非本进程持有),返回错误而非盲目续期。
func (*RedisLock) ExtendLockWithValue ¶
func (l *RedisLock) ExtendLockWithValue(ctx context.Context, key, value string, ttl time.Duration) (bool, error)
ExtendLockWithValue 续期:仅当 value 匹配(自己持有)才延长 TTL,返回是否成功续期。 供 watchdog 在长任务期间周期性续期,避免锁过期被别人抢走。
func (*RedisLock) LockWithTTL ¶
func (*RedisLock) TryLockWithTTL ¶
type RedisPoolOptions ¶
type RedisPoolOptions struct {
PoolSize int // 连接池大小,默认 10*GOMAXPROCS
MinIdleConns int // 最小空闲连接数,默认 0(冷启动无预热)
DialTimeoutSec int // 建连超时秒数,默认使用 OS TCP 超时
ReadTimeoutSec int // 读超时秒数
WriteTimeoutSec int // 写超时秒数
}
RedisPoolOptions 连接池可选配置,零值使用 go-redis 默认。
Click to show internal directories.
Click to hide internal directories.