Documentation ¶
Index ¶
- Variables
- type DelayFunc
- type ErrNodeTaken
- type ErrTaken
- 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) SetVersion(version int64) (bool, error)
- func (m *Mutex) SetVersionContext(ctx context.Context, version int64) (bool, error)
- func (m *Mutex) Unlock() (bool, error)
- func (m *Mutex) UnlockContext(ctx context.Context) (bool, error)
- func (m *Mutex) UnlockVersion(version int64) (bool, error)
- func (m *Mutex) UnlockVersionContext(ctx context.Context, version int64) (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) Version() int64
- 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 WithVersion(v int64) Option
- type OptionFunc
- type RedisError
- 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 DelayFunc ¶ added in v1.4.3
A DelayFunc is used to decide the amount of time to wait between retries.
type ErrNodeTaken ¶ added in v1.4.9
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.4.9
func (err ErrNodeTaken) Error() string
type ErrTaken ¶ added in v1.4.9
type ErrTaken struct {
Nodes []int
}
ErrTaken happens when the lock is already taken in a quorum on nodes.
type Mutex ¶
type Mutex struct {
// contains filtered or unexported fields
}
A Mutex is a distributed mutual exclusion lock.
func (*Mutex) ExtendContext ¶ added in v1.4.3
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 ¶ added in v1.4.3
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) SetVersionContext ¶ added in v1.4.4
func (*Mutex) UnlockContext ¶ added in v1.4.3
UnlockContext unlocks m and returns the status of unlock.
func (*Mutex) UnlockVersion ¶ added in v1.4.5
func (*Mutex) UnlockVersionContext ¶ added in v1.4.5
func (*Mutex) Until ¶ added in v1.4.9
Until returns the time of validity of acquired lock. The value will be zero value until a lock is acquired.
func (*Mutex) Valid
deprecated
added in
v1.4.3
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
added in
v1.4.3
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 ¶ added in v1.4.3
WithDriftFactor can be used to set the clock drift factor.
func WithExpiry ¶ added in v1.4.3
WithExpiry can be used to set the expiry of a mutex to the given value.
func WithGenValueFunc ¶ added in v1.4.3
WithGenValueFunc can be used to set the custom value generator.
func WithRetryDelay ¶ added in v1.4.3
WithRetryDelay can be used to set the amount of time to wait between retries.
func WithRetryDelayFunc ¶ added in v1.4.3
WithRetryDelayFunc can be used to override default delay behavior.
func WithTimeoutFactor ¶ added in v1.4.9
WithTimeoutFactor can be used to set the timeout factor.
func WithTries ¶ added in v1.4.3
WithTries can be used to set the number of times lock acquire is attempted.
func WithVersion ¶ added in v1.4.3
WithVersion can be used to assign the random value without having to call lock. This allows the ownership of a lock to be "transferred" and allows the lock to be unlocked from elsewhere.
type RedisError ¶ added in v1.4.9
A RedisError is an error communicating with one of the Redis nodes.
func (RedisError) Error ¶ added in v1.4.9
func (err RedisError) Error() string