Documentation
¶
Index ¶
Constants ¶
View Source
const ( // LockTimeout is the expiration of a redis lock if any operation is longer // than this, it should refresh the lock. LockTimeout = 20 * time.Second // WaitTimeout is the maximum time to wait before returning control to caller. WaitTimeout = 1 * time.Minute // WaitRetry is the time to wait between retries. WaitRetry = 100 * time.Millisecond )
Variables ¶
View Source
var ( // ErrTooManyRetries is the error returned when despite several tries // we never managed to get a lock ErrTooManyRetries = errors.New("abort after too many failures without getting the lock") )
Functions ¶
This section is empty.
Types ¶
type ErrorLocker ¶
type ErrorLocker interface {
Lock() error
Unlock()
}
An ErrorLocker is a locker which can fail (returns an error)
type ErrorRWLocker ¶
type ErrorRWLocker interface {
ErrorLocker
RLock() error
RUnlock()
}
ErrorRWLocker is the interface for a RWLock as inspired by RWMutex
type Getter ¶
type Getter interface {
// ReadWrite returns the read/write lock for the given name.
// By convention, the name should be prefixed by the instance domain on which
// it applies, then a slash and the package name (ie alice.example.net/vfs).
ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker
// LongOperation returns a lock suitable for long operations. It will refresh
// the lock in redis to avoid its automatic expiration.
LongOperation(db prefixer.Prefixer, name string) ErrorLocker
}
Getter returns a lock on a resource matching the given `name`.
func New ¶
func New(client redis.UniversalClient) Getter
type InMemoryLockGetter ¶
type InMemoryLockGetter struct {
// contains filtered or unexported fields
}
func NewInMemory ¶
func NewInMemory() *InMemoryLockGetter
func (*InMemoryLockGetter) LongOperation ¶
func (i *InMemoryLockGetter) LongOperation(db prefixer.Prefixer, name string) ErrorLocker
LongOperation returns a lock suitable for long operations. It will refresh the lock in redis to avoid its automatic expiration.
func (*InMemoryLockGetter) ReadWrite ¶
func (i *InMemoryLockGetter) ReadWrite(_ prefixer.Prefixer, name string) ErrorRWLocker
type RedisLockGetter ¶
type RedisLockGetter struct {
// contains filtered or unexported fields
}
func NewRedisLockGetter ¶
func NewRedisLockGetter(client redis.UniversalClient) *RedisLockGetter
func (*RedisLockGetter) LongOperation ¶
func (r *RedisLockGetter) LongOperation(db prefixer.Prefixer, name string) ErrorLocker
LongOperation returns a lock suitable for long operations. It will refresh the lock in redis to avoid its automatic expiration.
func (*RedisLockGetter) ReadWrite ¶
func (r *RedisLockGetter) ReadWrite(db prefixer.Prefixer, name string) ErrorRWLocker
Click to show internal directories.
Click to hide internal directories.