Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrConnection is returned by Locker methods in case of problems with redis. ErrConnection = errors.New("redis connection error") // ErrTimeout is returned by Locker methods if timeout was specified and was exceeded while waiting for lock. ErrTimeout = errors.New("timeout exceeded but lock not acquired") // ErrInterrupted is returned by Locker methods if they were interrupted via Context. ErrInterrupted = errors.New("interrupted") // ErrNotReleased is returned by locker methods if lock was not released. ErrNotReleased = errors.New("lock was not released") // ErrUnknownMode is return by locker methods in case the lock was set to unknown mode. ErrUnknownMode = errors.New("lock is in unknown mode") )
Functions ¶
This section is empty.
Types ¶
type Locker ¶
type Locker interface { // Read executes given function with shared reader access. Read(fn func()) error // Write executes given function with unique writer access. Write(fn func()) error }
Locker allows to execute given functions at reader or writer access privilege.
type Options ¶
type Options struct { // LockTTL sets lock duration timeout. // This allows to release the lock even if whole program crashes. // Recommended not to make it too big or too small as it may affect performance. // It should be less than RetryCount * RetryInterval in order to avoid undesired ErrTimeouts. // Minimum: 100 milliseconds // Default: 1 second LockTTL time.Duration // RetryCount limits number of attempts to acquire lock. // Default: 200 RetryCount int // RetryInterval sets interval between attemts to acquire lock. // Minimum: 1 millisecond // Default: 10 milliseconds RetryInterval time.Duration // Context of the execution. // Default: Background Context context.Context // AppID is used as writer lock token prefix. // Used for debugging. AppID string // ReaderLockToken should be the same for all readers group. // You can override default token here to create subgroups of readers. ReaderLockToken string // Mode of the lock behavior. // Defaults to writer-preferring behavior in order not to break back compatibility. // Default: ModePreferWriter Mode Mode }
Options used to configure locker.
Click to show internal directories.
Click to hide internal directories.