Code Monkey home page Code Monkey logo

locker's Introduction

locker

Distributed redis lock.

import (
	"github.com/xh3b4sd/locker/lock"
	"github.com/xh3b4sd/locker/pool"
)

func main() {
	var err error

	// Initialize a new locker instance that can be reused for different locks.
	// Every locker requires a redis connection pool.
	var loc locker.Interface
	{
		loc = lock.New(lock.Config{
			Poo: pool.New(),
		})
	}

	// Keys define a lock scope. They are used to distinguish different locks.
	var key string
	{
		key = "key"
	}

	// Creating a lock returns a unique lock value that can be used to extend an
	// existing lock as well as to verify whether a specific lock exists.
	var val string
	{
		val, err = loc.Create(key)
		if err != nil {
			panic(err)
		}
	}

	// Extending the lock can be done using its key and value.
	{
		err = loc.Extend(key, val)
		if err != nil {
			panic(err)
		}
	}

	// Locks can be deleted in order to free the lock key for further locking.
	{
		err = loc.Delete(key)
		if err != nil {
			panic(err)
		}
	}
}

Conformance Tests

docker run --rm --name redis-stack -p 6379:6379 -p 8001:8001 redis/redis-stack:latest
go test ./... -race -tags redis

Redis Port

export REDIS_PORT=6381
docker run --rm --name redis-stack-rescue -p 6381:6379 -p 8003:8001 redis/redis-stack:latest

locker's People

Contributors

xh3b4sd avatar dependabot[bot] avatar

Watchers

 avatar  avatar

locker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.