0.2.2 • Published 8 years ago

node-mutex v0.2.2

Weekly downloads
167
License
-
Repository
github
Last release
8 years ago

node-mutex

Build Status npm version

How to install

npm install node-mutex

node-mutex ensures synchronicity of critical code blocks across multiple nodejs instances. This is achieved with the help of redis and some clever aproach to managing locks.

How to use

var mutex = require( 'node-mutex' )();

mutex.lock( 'key', function( err, unlock ) {
  if ( err ) {
  	console.error( err );
  	console.error( 'Unable to acquire lock' );
  }
  //synchronized code block

  unlock();
});

How to use ( Promise API )

var mutex = require( 'node-mutex' )();

mutex
  .lock( 'key' )
  .then( function( unlock ) {

    //synchronized code block

  	unlock();
  } );

Options

var mutex = require('node-mutex')(opts);

List of available options:

  • host: host to connect redis on (127.0.0.1)
  • port: port to connect redis on (6379)
  • url: url to connect redis, this option replace values of host and port. Format: [redis:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]
  • prefix: port to connect redis on (mutex:)
  • sleepTime: maximum time in milliseconds to wait before retrying the acquisition of lock (250)
  • expireTime: time in milliseconds before the lock expires (3000)
  • pub: optional, the redis client to publish events on
  • sub: optional, the redis client to subscribe to events on

License

MIT

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago