Documentation ¶
Index ¶
- Variables
- func SplitKey(uniqKey string) (namespace, key string)
- type Config
- type DelayFunc
- type Error
- type ErrorKind
- type InMemory
- type Mutex
- type MutexManager
- type Option
- func WithDriftFactor(factor float64) Option
- func WithExpiry(expiry time.Duration) Option
- func WithGenValueFunc(genValueFunc func() (string, error)) Option
- func WithNamespace(ns string) 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 Provider
- type Redis
- type RedisMutex
Constants ¶
This section is empty.
Variables ¶
var WireSet = wire.NewSet( ProvideMutexManager, )
Functions ¶
Types ¶
type ErrorKind ¶
type ErrorKind string
ErrorKind enum displays human readable message in error.
const ( ErrorKindLockHeld ErrorKind = "lock already held" ErrorKindLockNotHeld ErrorKind = "lock not held" ErrorKindProviderError ErrorKind = "lock provider error" ErrorKindCannotLock ErrorKind = "timeout while trying to acquire lock" ErrorKindContext ErrorKind = "context error while trying to acquire lock" ErrorKindMaxRetriesExceeded ErrorKind = "max retries exceeded to acquire lock" ErrorKindGenerateTokenFailed ErrorKind = "token generation failed" )
type InMemory ¶
type InMemory struct {
// contains filtered or unexported fields
}
InMemory is a local implementation of a MutexManager that it's intended to be used during development.
func NewInMemory ¶
NewInMemory creates a new InMemory instance only used for development.
type Mutex ¶
type Mutex interface { // Key returns the key to be locked. Key() string // Lock acquires the lock. It fails with error if the lock is already held. Lock(ctx context.Context) error // Unlock releases the lock. It fails with error if the lock is not currently held. Unlock(ctx context.Context) error }
type MutexManager ¶
type MutexManager interface { // NewMutex creates a mutex for the given key. The returned mutex is not held // and must be acquired with a call to .Lock. NewMutex(key string, options ...Option) (Mutex, error) }
MutexManager describes a Distributed Lock Manager.
func ProvideMutexManager ¶
func ProvideMutexManager(config Config, client redis.UniversalClient) MutexManager
type Option ¶
type Option interface {
Apply(*Config)
}
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 WithNamespace ¶
WithNamespace returns an option that configures Mutex.ns.
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 Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis wrapper for redsync.
type RedisMutex ¶
type RedisMutex struct {
// contains filtered or unexported fields
}