autolock

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 5 Imported by: 0

README

autolock

Build Status Coverage Status GoDoc Release Go Report Card

Package autolock implements a small wrapper over github.com/bsm/redis-lock to automatically refresh locks.

Documentation

Overview

Package autolock implements a small wrapper over github.com/bsm/redis-lock to automatically refresh locks.

Index

Constants

This section is empty.

Variables

View Source
var ErrLostLock = errors.New("lost lock")

ErrLostLock is returned if the lock has been lost to another process.

Functions

This section is empty.

Types

type Lock

type Lock struct {
	// contains filtered or unexported fields
}

Lock is returned by Acquire and represents an active lock.

func Acquire

func Acquire(client *redis.Client, key string, options *Options) (*Lock, error)

Acquire will attempt to the lock represented by the specified key. It will retry the acquisition using the configured delay. The returned lock is automatically refreshed until it is released. If the lock attempt failed nil is returned.

func (*Lock) Abandoned

func (l *Lock) Abandoned() <-chan struct{}

Abandoned returns a channel that is closed when the lock has been abandoned. The closing of this channel does not necessarily mean that the lock has been successfully released.

func (*Lock) Release

func (l *Lock) Release() error

Release will release the lock.

func (*Lock) Status

func (l *Lock) Status() (bool, error)

Status reports the state of the lock.

type Options

type Options struct {
	// The time after a lock will release itself.
	//
	// Default: 5s
	LockTimeout time.Duration

	// The amount of initial retries to acquire the lock.
	//
	// Default: 0
	RetryCount int

	// The delay between individual attempts to acquire the lock.
	//
	// Default: 100ms
	RetryDelay time.Duration

	// The interval of the refresh cycle. Should be considerably smaller than
	// the LockTimeout to ensure the lock is refreshed.
	//
	// Default: LockTimeout / 2 (2.5s)
	RefreshInterval time.Duration
}

Options is used to configure the lock acquisition, refresh and release.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL