mutex

package module
v0.0.0-...-2c6cf6a Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2015 License: MIT Imports: 8 Imported by: 0

README

About

This is a distributed mutex library for the Go programming language (http://golang.org/).

Now only support Memcached.

Installing

Using go get

$ go get github.com/bradfitz/gomemcache/memcache
$ go get github.com/harrykobe/mutex

After this command mutex is ready to use. Its source will be in:

$GOPATH/src/github.com/harrykobe/mutex

Example

import (
        "github.com/bradfitz/gomemcache/memcache"
        "github.com/harrykobe/mutex"
)

func main() {
    mc := memcache.New("127.0.0.1:11211")
      mmutex := NewMemcacheMutex("test", mc)
      mmutex.Lock()
       ...
      mmutex.Unlock()
}

Full docs, see:

Coming soon...

Documentation

Index

Constants

View Source
const (
	// DefaultExpiry is used when Mutex Duration is 0
	DefaultExpiry = 8 * time.Second
	// DefaultTries is used when Mutex Duration is 0
	DefaultTries = 16
	// DefaultDelay is used when Mutex Delay is 0
	DefaultDelay = 512 * time.Millisecond
	// DefaultFactor is used when Mutex Factor is 0
	DefaultFactor = 0.01
)
View Source
const (
	DomainPerson = iota
	DomainGroup
	DomainOrg
)

Variables

View Source
var (
	// ErrFailed is returned when lock cannot be acquired
	ErrFailed = errors.New("failed to acquire lock")
)

Functions

func SetDefaultMemcache

func SetDefaultMemcache(client *memcache.Client)

Types

type Locker

type Locker interface {
	Lock() error
	Unlock()
}

Locker interface with Lock returning an error when lock cannot be aquired

type MemcacheRWMutex

type MemcacheRWMutex struct {
	RWMutex
	// contains filtered or unexported fields
}

func NewMemcacheMutex

func NewMemcacheMutex(name string, clients ...*memcache.Client) (mRWMutex *MemcacheRWMutex)

func (*MemcacheRWMutex) Lock

func (this *MemcacheRWMutex) Lock() error

func (*MemcacheRWMutex) Unlock

func (this *MemcacheRWMutex) Unlock()

type RWMutex

type RWMutex struct {
	Name   string
	Expiry time.Duration

	Tries int           // Number of attempts to acquire lock before admitting failure, DefaultTries if 0
	Delay time.Duration // Delay between two attempts to acquire lock, DefaultDelay if 0

	Factor float64 // Drift factor, DefaultFactor if 0
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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