nodemailer/redfour

Name: redfour

Owner: nodemailer

Description: A redis binary semaphore with async wait

Forked from: mixmaxhq/redfour

Created: 2017-10-03 07:11:44.0

Updated: 2018-04-16 18:27:58.0

Pushed: 2017-10-03 08:11:21.0

Homepage: null

Size: 38

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ioredfour

Originally forked from redfour. Main difference being that redfour uses node_redis + node-redis-scripty while ioredfour uses ioredis.

Install

or

install ioredfour --save
Usage example
Lock = require('ioredfour');

testLock = new Lock({
 Can also be an `Object` of options to pass to `new Redis()`
 https://www.npmjs.com/package/ioredis#connect-to-redis, or an existing
 instance of `ioredis` (if you want to reuse one connection, though this
 module must create a second).
dis: 'redis://localhost:6379',
mespace: 'mylock'

id = Math.random();
firstlock;

irst, acquire the lock.
Lock.acquireLock(id, 60 * 1000 /* Lock expires after 60sec if not released */ , function(err, lock) {
 (err) {
console.log('error acquiring', err);
else if (!lock.success) {
console.log('lock exists', lock);
else {
console.log('lock acquired initially');
firstlock = lock;



nother server might be waiting for the lock like this.
Lock.waitAcquireLock(id, 60 * 1000 /* Lock expires after 60sec */ , 10 * 1000 /* Wait for lock for up to 10sec */ , function(err, lock) {
 (err) {
console.log('error wait acquiring', err);
else {
console.log('lock acquired after wait!', lock);



hen the original lock is released, `waitAcquireLock` is fired on the other server.
imeout(() => {
stLock.releaseLock(firstlock, (err) => {
if (err) {
  console.log('error releasing', err);
} else {
  console.log('released lock');
}
;
 * 1000);
Contributing

We welcome pull requests! Please lint your code.

Release History
Etymology

Shortened (and easier to pronouce) version of “Redis Semaphore”


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.