Documentation
¶
Index ¶
- type LockOption
- type LockOptions
- type RLock
- func (l *RLock) BlockWaitingSecond() time.Duration
- func (l *RLock) ExpireTime() time.Duration
- func (l *RLock) Key() string
- func (l *RLock) Lock() int64
- func (l *RLock) SetBlockWaitingSecond(blockWaitingTime time.Duration) *RLock
- func (l *RLock) SetExpireTime(expireTime time.Duration) *RLock
- func (l *RLock) SetKey(key string) *RLock
- func (l *RLock) SetToken(token string) *RLock
- func (l *RLock) SetWatchdogSwitch(watchdogSwitch bool) *RLock
- func (l *RLock) Token() string
- func (l *RLock) TryLock() int64
- func (l *RLock) UnLock() int64
- func (l *RLock) WatchdogSwitch() bool
- type RedLock
- type RedisClientOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockOption ¶ added in v1.0.1
type LockOption func(*LockOptions)
func WithBlockWaitingTime ¶ added in v1.0.1
func WithBlockWaitingTime(blockWaitingTime time.Duration) LockOption
func WithExpireTime ¶ added in v1.0.1
func WithExpireTime(expireTime time.Duration) LockOption
func WithWatchDogSwitch ¶ added in v1.0.1
func WithWatchDogSwitch(watchdogSwitch bool) LockOption
type LockOptions ¶ added in v1.0.1
type LockOptions struct {
// contains filtered or unexported fields
}
type RLock ¶
type RLock struct {
LockOptions
// contains filtered or unexported fields
}
func NewRLock ¶
func NewRLock(op RedisClientOptions, key string, opts ...LockOption) (rLock *RLock)
NewRLock new a redis lock. You can set params with set function.
Default lockOptions:
blockWaitingTime : 60 * time.Second expireTime : 30 * time.Second watchdogSwitch : false
func (*RLock) BlockWaitingSecond ¶
func (*RLock) ExpireTime ¶
func (*RLock) Lock ¶
Lock try to acquire lock, until acquire lock or blocking timeout. Returns:
1. ttl < 0 error;
2. ttl = 0 success;
3. ttl > 0 acquire by others
func (*RLock) SetBlockWaitingSecond ¶
func (*RLock) SetWatchdogSwitch ¶
func (*RLock) TryLock ¶
TryLock try to acquire lock in once, support reentrant. Returns:
1. ttl < 0 error;
2. ttl = 0 success;
3. ttl > 0 acquire by others.
func (*RLock) UnLock ¶
UnLock try to release lock, support reentrant. Returns:
1. res < 0 error or release other's lock;
2. res = 0 release lock success, but still hold lock because of reentry;
3. res = 1 release lock success absolutely.
func (*RLock) WatchdogSwitch ¶
type RedLock ¶
type RedLock struct {
// contains filtered or unexported fields
}
func NewRedLock ¶
func NewRedLock(rcs []RedisClientOptions, key string, expireTime time.Duration) (redLock *RedLock, err error)
NewRedLock new a RedLock from multi redis servers.
It is required that the cumulative timeout threshold of all nodes is less than one-tenth of the distributed lock expiration time.