Documentation ¶
Overview ¶
Package redsync provides a Redis-based distributed mutual exclusion lock implementation as described in the post http://redis.io/topics/distlock.
Values containing the types defined in this package should not be copied.
Index ¶
- Variables
- type DelayFunc
- 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)deprecated
- func (m *Mutex) ValidContext(ctx context.Context) (bool, error)deprecated
- 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 Redsync
Constants ¶
This section is empty.
Variables ¶
var ErrExtendFailed = errors.New("redsync: failed to extend lock")
ErrExtendFailed is the error resulting if Redsync fails to extend the lock.
var ErrFailed = errors.New("redsync: 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 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
deprecated
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.
Deprecated: Use Until instead. See https://github.com/go-redsync/redsync/issues/72.
func (*Mutex) ValidContext
deprecated
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.
Deprecated: Use Until instead. See https://github.com/go-redsync/redsync/issues/72.
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.