Socket
Book a DemoInstallSign in
Socket

rlock

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rlock

distributed lock for nodejs using redis

0.0.5
latest
Source
npmnpm
Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

rlock

Distributed lock for nodejs using redis

Usage example

var rlock = require('rlock');
var lock = new rlock.Lock('rlock.key');
lock.acquire(function(err, done) {
	if (!done) {
		return console.log('Could not acquire lock');
	}
	// Do stuffs
	done();
	// OR
	done(function(err, ok){
		console.log(ok);
	});
	// OR
	lock.release(function(err, ok){
		console.log(ok);
	});
});
// Set global redis client, with your own setting
var rlock = require('rlock');
var redis = require('redis');
rlock.setRedisClient(redis.createClient(6378));

API

Lock(key, options)

  • key String
  • options Object, optional.

Available option:

  • maxRetries Maximum number of retries if can not acquire the lock, specify 0 if no retry, default 10.
  • retryDelay Number of milliseconds to wait until next try, default 50 milliseconds.
  • timeout Number of milliseconds before the lock expires, default 5000 milliseconds.
  • rclient Instance of redis client, see https://github.com/mranney/node_redis#rediscreateclientport-host-options. If not specified it will create a client with default config (or the global one if set). Be aware that redis.createClient crashes on error if not handle.

Lock.acquire(callback)

  • callback Function(err, done) success if and only if done is a function. Can use it to release the lock.

Lock.release(callback)

  • callback Function(err, ok) ok true if success. Callback is optional. This can only call if Lock.acquire was successful.

setRedisClient(client)

Keywords

lock

FAQs

Package last updated on 01 Mar 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.