redlock

package module
v0.0.0-...-22fd0d9 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2016 License: MIT Imports: 5 Imported by: 1

README

redlock GoDoc

Redlock implements a simple mutex on a single redis instance. I got rid of the gocover badge because the tests don't work without a redis instance.

Documentation

Overview

Package redlock implements a simple mutex on a single redis instance, using a connection pool for performance and efficiency.

Note that this design does not guarantee correctness. It is lightweight and appropriate for use cases where two clients holding the same lock simultaneously is not a critical issue. It is possible, in cases of processes running overlong, or the redis node's failure, for more than one process to hold a given lock simultaneously. This should happen only very rarely, but it can happen.

Index

Constants

This section is empty.

Variables

View Source
var ConfigNotSetError string = "No redis config set."

Functions

This section is empty.

Types

type RedisConfig

type RedisConfig struct {
	Address        string // address:port
	Database       int    // database number to connect to
	KeyPrefix      string // optional prefix applied to keys
	ConnectTimeout time.Duration
}

type Redlock

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

func New

func New(conf *RedisConfig) (rl *Redlock)

New returns a redlock instance. It is the consumer's responsibility to close the Redlock's connection pool via Close() if possible.

func (*Redlock) Close

func (rl *Redlock) Close() (err error)

Close the Redlock's redis pool.

func (*Redlock) Lock

func (rl *Redlock) Lock(key string, timeout time.Duration) (acquired bool, err error)

Lock tries to acquire a lock on the given connection for the key via SETNX as discussed at http://redis.io/commands/setnx, returning true if successful. Timeout is given in milliseconds.

func (*Redlock) Renew

func (rl *Redlock) Renew(key string, timeout time.Duration) (renewed bool, err error)

Extend the time on a given lock - only to be called by lock's current holder or delegate

func (*Redlock) Unlock

func (rl *Redlock) Unlock(key string) (err error)

Unlock deletes the given lock key, releasing the lock.

func (*Redlock) WaitLock

func (rl *Redlock) WaitLock(key string, timeout time.Duration, retryInterval time.Duration) (acquired bool, err error)

WaitLock locks the given key for timeout duration, retrying the lock until it succeeds waiting retryInterval duration between retries.

Jump to

Keyboard shortcuts

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