Documentation
¶
Index ¶
- Variables
- type DelayFunc
- type ErrNodeTaken
- type ErrTaken
- type Lock
- type Mutex
- func (m *Mutex) Extend() (bool, error)
- func (m *Mutex) ExtendContext(ctx context.Context) (bool, error)
- func (m *Mutex) Lock() error
- func (m *Mutex) LockContext(ctx context.Context) error
- func (m *Mutex) Name() string
- func (m *Mutex) Unlock() (bool, error)
- func (m *Mutex) UnlockContext(ctx context.Context) (bool, error)
- func (m *Mutex) Until() time.Time
- func (m *Mutex) Valid() (bool, error)
- func (m *Mutex) ValidContext(ctx context.Context) (bool, error)
- func (m *Mutex) Value() string
- type Option
- func WithDriftFactor(factor float64) Option
- func WithExpiry(expiry time.Duration) Option
- func WithGenValueFunc(genValueFunc func() (string, error)) Option
- func WithRetryDelay(delay time.Duration) Option
- func WithRetryDelayFunc(delayFunc DelayFunc) Option
- func WithTimeoutFactor(factor float64) Option
- func WithTries(tries int) Option
- func WithValue(v string) Option
- type OptionFunc
- type RedisError
Constants ¶
This section is empty.
Variables ¶
var ErrExtendFailed = errors.New("redislock: failed to extend lock")
ErrExtendFailed is the error resulting if Redsync fails to extend the lock.
var ErrFailed = errors.New("redislock: failed to acquire lock")
ErrFailed is the error resulting if Redsync fails to acquire the lock after exhausting all retries.
Functions ¶
This section is empty.
Types ¶
type ErrNodeTaken ¶ added in v1.0.2
type ErrNodeTaken struct {
Node int
}
ErrNodeTaken is the error resulting if the lock is already taken in one of the cluster's nodes
func (ErrNodeTaken) Error ¶ added in v1.0.2
func (err ErrNodeTaken) Error() string
type ErrTaken ¶ added in v1.0.2
type ErrTaken struct {
Nodes []int
}
ErrTaken happens when the lock is already taken in a quorum on nodes.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock provides a simple method for creating distributed mutexes using multiple Redis connection pools.
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
A Mutex is a distributed mutual exclusion lock.
func (*Mutex) ExtendContext ¶
ExtendContext resets the mutex's expiry and returns the status of expiry extension.
func (*Mutex) Lock ¶
Lock locks m. In case it returns an error on failure, you may retry to acquire the lock by calling this method again.
func (*Mutex) LockContext ¶
LockContext locks m. In case it returns an error on failure, you may retry to acquire the lock by calling this method again.
func (*Mutex) UnlockContext ¶
UnlockContext unlocks m and returns the status of unlock.
func (*Mutex) Until ¶
Until returns the time of validity of acquired lock. The value will be zero value until a lock is acquired.
func (*Mutex) Valid ¶
Valid returns true if the lock acquired through m is still valid. It may also return true erroneously if quorum is achieved during the call and at least one node then takes long enough to respond for the lock to expire.
func (*Mutex) ValidContext ¶
ValidContext returns true if the lock acquired through m is still valid. It may also return true erroneously if quorum is achieved during the call and at least one node then takes long enough to respond for the lock to expire.
type Option ¶
type Option interface {
Apply(*Mutex)
}
An Option configures a mutex.
func WithDriftFactor ¶
WithDriftFactor can be used to set the clock drift factor.
func WithExpiry ¶
WithExpiry can be used to set the expiry of a mutex to the given value.
func WithGenValueFunc ¶
WithGenValueFunc can be used to set the custom value generator.
func WithRetryDelay ¶
WithRetryDelay can be used to set the amount of time to wait between retries.
func WithRetryDelayFunc ¶
WithRetryDelayFunc can be used to override default delay behavior.
func WithTimeoutFactor ¶
WithTimeoutFactor can be used to set the timeout factor.
type RedisError ¶ added in v1.0.2
A RedisError is an error communicating with one of the Redis nodes.
func (RedisError) Error ¶ added in v1.0.2
func (err RedisError) Error() string