shared-lock

0.0.3 • Public • Published

shared-lock

Shared local/distributed lock to reduce redis load and write() syscalls.

Installation

$ npm install shared-lock

Example

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

for (var i = 0; i < 25; i++) {
  (function(i){
    request('tobi:abby', function(){
      console.log('finished tobi:abby %s', i);
    });
  })(i);
}

function request(key, fn) {
  var lock = Lock({
    key: 'marketo:' + key,
    redis: db
  });

  lock.lock(function(err){
    // faux work
    setTimeout(function(){
      lock.unlock(fn);
    }, 500);
  });
}

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i shared-lock

Weekly Downloads

0

Version

0.0.3

License

MIT

Last publish

Collaborators

  • tjholowaychuk