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 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 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 NewRedisLock ¶
func (*RedisLock) ExtendLock ¶
func (*RedisLock) ExtendLockWithValue ¶ added in v1.5.5
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 ¶
Click to show internal directories.
Click to hide internal directories.