redisync

package module
v0.0.0-...-cdc7c96 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2013 License: BSD-2-Clause-Views Imports: 5 Imported by: 1

README

Redisync

A Go package which implements synchronization functions on top of Redis. The heavy lifting is done with Lua scripts to make the elimination of race conditions easier.

Note: When using a TTL, the user should take care to finsih execution before the TTL.

Install

$ go install github.com/ryandotsmith/redisync

Usage

See: ./example_test.go

Documentation

GoDoc

Hacking on Redisync

Build Status

$ go version
go version go1.1.1 darwin/amd64
$ ./redis-server --version
Redis server v=2.6.14 sha=00000000:0 malloc=libc bits=64
$ git clone git://github.com/ryandotsmith/redisync.git
$ go get ./...
$ ./redis-server &
$ go test

Documentation

Overview

Synchronization built on top of Redis. Depends on github.com/garyburd/redigo/redis

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mutex

type Mutex struct {
	// The key used in Redis.
	Name string
	// The amount of time before Redis will expire the lock.
	Ttl time.Duration
	// The time to sleep before retrying a lock attempt.
	Backoff time.Duration
	// contains filtered or unexported fields
}

func NewMutex

func NewMutex(name string, ttl time.Duration) *Mutex

Each lock will have a name which corresponds to a key in the Redis server. The mutex will also be initialized with a uuid. The mutex uuid can be used to extend the TTL for the lock.

func (*Mutex) Lock

func (m *Mutex) Lock(c redis.Conn)

With similar behaviour to Go's sync pkg, this function will sleep until TryLock() returns true. The connection will be used once to execute the lock script.

func (*Mutex) TryLock

func (m *Mutex) TryLock(c redis.Conn) bool

Makes a single attempt to acquire the lock. Locking a mutex which has already been locked using the mutex uuid will result in the TTL of the mutex being extended. The connection will be used once to execute the lock script.

func (*Mutex) Unlock

func (m *Mutex) Unlock(c redis.Conn) (bool, error)

If the local mutex uuid matches the uuid in Redis, the lock will be deleted. The connection will be used once to execute the unlock script.

Jump to

Keyboard shortcuts

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