mgolock

package module
v0.0.0-...-66db2f6 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2015 License: GPL-2.0 Imports: 4 Imported by: 0

README

mgolock

Dead simple mutex locking for any MongoDB collection. An alternative to caching the mutexes in Redis or Mongo, operates directly on the document with minimal trace. Yeah i don't like ORMs, this is enough. Docs to come shortly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCantLock = errors.New("Can't lock the requested document")

Functions

This section is empty.

Types

type LockedC

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

a mutex locked collection

func MakeLockedC

func MakeLockedC(c *mgo.Collection) *LockedC

func (*LockedC) GetIdLocked

func (lc *LockedC) GetIdLocked(id interface{}, d time.Duration, result interface{}) error

tries to lock document identified with id with a d timeout, populates result with the document

func (*LockedC) Unlock

func (lc *LockedC) Unlock(id interface{}) error

unlocks a locked document if lock is still ours

func (*LockedC) UpdateId

func (lc *LockedC) UpdateId(id interface{}, update interface{}) error

updates a locked document if lock is still ours, this must be a SAFE update(with update operators), otherwise the lock will be overwritten (the update will go ok but you'll lose the lock)

Jump to

Keyboard shortcuts

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