lock

package
v0.0.0-...-09d934d Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultDuration is the default duration of the lock
	DefaultDuration = 10 * time.Second
	// DefaultAttempts is the default attempts for acquiring lock
	DefaultAttempts = 7
	// DefaultDelay is the default delay between attempts
	DefaultDelay = 512 * time.Millisecond
	// DefaultFactor is the default drift factor
	DefaultFactor = 0.01
)

Variables

View Source
var (
	// ErrLockFailedAfterMaxAttempts is the error for failing to acquire the lock after maximum attempts
	ErrLockFailedAfterMaxAttempts = errors.New("Lock Error: fail to acquire lock after maximum attempts!")
	// ErrLockExtensionFailed is the error for failing to extend the lock
	ErrLockExtensionFailed = errors.New("Lock Error: lock extension failed!")
	// ErrLockLost is the error for lock lost during auto renewal
	ErrLockLost = errors.New("Lock Error: lock is lost during auto renewal!")
)
View Source
var (
	// LockARCommandStop is the command for stopping the auto renew timer
	LockARCommandStop = "STOP"
	// LockARSignalStopSuccess is the signal for a successful stop
	LockARSignalStopSuccess = "STOPSuccess"
)

Functions

This section is empty.

Types

type Lock

type Lock struct {
	Key         string        // redis key
	Duration    time.Duration // duration of the lock
	Factor      float64       // drif factor
	MaxAttempts int           // maxmium attempts to acquire the lock before failure
	Delay       time.Duration // delay between attempts
	AutoRenew   bool          // whether to auto renew the lock

	Client *redis.Pool // the redis client

	ARControl chan string // auto renew control channel
	ARResult  chan string // auto renew result channel
	// contains filtered or unexported fields
}

Lock is a lock on a key

func NewLockOnKey

func NewLockOnKey(client *redis.Pool, key string, ar bool) *Lock

NewLockOnKey creates a lock struct (unacquired) on a key

func (*Lock) Get

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

Get attempts to acquire lock on the key

func (*Lock) Release

func (l *Lock) Release()

Release revokes the lock on the key

Jump to

Keyboard shortcuts

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