redsync

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: BSD-3-Clause Imports: 6 Imported by: 0

README

Redsync

Build Status

Redsync provides a Redis-based distributed mutual exclusion lock implementation for Go as described in this post. A reference library (by antirez) for Ruby is available at github.com/antirez/redlock-rb.

Installation

Install Redsync using the go get command:

$ go get gopkg.in/redsync.v1

The only dependencies are the Go distribution and Redigo.

Documentation

Contributing

Contributions are welcome.

License

Redsync is available under the BSD (3-Clause) License.

Disclaimer

This code implements an algorithm which is currently a proposal, it was not formally analyzed. Make sure to understand how it works before using it in production environments.

Documentation

Overview

Package redsync provides a Redis-based distributed mutual exclusion lock implementation as described in the post http://redis.io/topics/distlock.

Values containing the types defined in this package should not be copied.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailed = errors.New("redsync: failed to acquire lock")

Functions

This section is empty.

Types

type Mutex

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

A Mutex is a distributed mutual exclusion lock.

func (*Mutex) Extend

func (m *Mutex) Extend() bool

Extend resets the mutex's expiry and returns the status of expiry extension. It is a run-time error if m is not locked on entry to Extend.

func (*Mutex) Lock

func (m *Mutex) Lock() error

Lock locks m. In case it returns an error on failure, you may retry to acquire the lock by calling this method again.

func (*Mutex) Unlock

func (m *Mutex) Unlock() bool

Unlock unlocks m and returns the status of unlock. It is a run-time error if m is not locked on entry to Unlock.

type Option

type Option interface {
	Apply(*Mutex)
}

An Option configures a mutex.

func SetDriftFactor

func SetDriftFactor(factor float64) Option

SetDriftFactor can be used to set the clock drift factor.

func SetExpiry

func SetExpiry(expiry time.Duration) Option

SetExpiry can be used to set the expiry of a mutex to the given value.

func SetRetryDelay

func SetRetryDelay(delay time.Duration) Option

SetRetryDelay can be used to set the amount of time to wait between retries.

func SetTries

func SetTries(tries int) Option

SetTries can be used to set the number of times lock acquire is attempted.

type OptionFunc

type OptionFunc func(*Mutex)

OptionFunc is a function that configures a mutex.

func (OptionFunc) Apply

func (f OptionFunc) Apply(mutex *Mutex)

Apply calls f(mutex)

type Pool

type Pool interface {
	Get() redis.Conn
}

A Pool maintains a pool of Redis connections.

type Redsync

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

Redsync provides a simple method for creating distributed mutexes using multiple Redis connection pools.

func New

func New(pools []Pool) *Redsync

New creates and returns a new Redsync instance from given Redis connection pools.

func (*Redsync) NewMutex

func (r *Redsync) NewMutex(name string, options ...Option) *Mutex

NewMutex returns a new distributed mutex with given name.

Jump to

Keyboard shortcuts

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