2.0.0 • Published 8 years ago

nredis-lock v2.0.0

Weekly downloads
26
License
MIT
Repository
github
Last release
8 years ago

nredis-lock HackHands Live Coding Help Build Status npm version

Simple node.js lock based on Redis

NPM

Features

  • For better server compatibility this module doesn't use redis scripts

Installation

$ npm install nredis-lock

Initialization

var redis = require('redis');

var Lock = require('nredis-lock')(redis.createClient());

Lock(lockName, timeout = 5000)

  • lockName: Any name for a lock
  • timeout: (Optional) The maximum time (in ms) to hold the lock for. If this time is exceeded, the lock is automatically released. Default: 10000 ms (10 seconds).

Simple usage

// Acquire a lock.
Lock('lock-name')
	.acquire()
	.then(function(done){
		// Show time...
		// When you done, release the lock :D
		setTimeout(function(){
			done();
		}, 1000);
	}, function(){
		// There is a lock active
	});

Using custom timeout

  • the default timeout is 5000 (milliseconds)
// Using 3000 milliseconds as timeout
Lock('lock-name', 3000)
	.acquire()
	.then(function(done){
	}, function(){
	});

Release the lock any time

Lock('lock-name')
	.release()
	.then(function(){
		// Lock released
	}, function(){
		// No lock to release
	})

Tests

Require: redis-server running

$ npm test

Author

Assis Antunes <assixantunes@gmail.com>

License

(The MIT License)

Copyright (c) 2015 Assis Antunes (assixantunes@gmail.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago