Socket
Socket
Sign inDemoInstall

node-redis-lock

Package Overview
Dependencies
7
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    node-redis-lock

Node.js Redis locking tool.


Version published
Maintainers
2
Created

Readme

Source

node-redis-lock

Node.js redis locking system.

Installation

  $ npm install node-redis-lock

Use

const Lock = require('node-redis-lock');
const redis = require('redis');
const client = redis.createClient();

// Instantiate a lock.
let lock = new Lock({namespace: 'locking'}, client);

// Acquire a lock.
const key = 'job1';
const value = ['owned-by-',require('os').hostname()].join('');
const ttl = 1; // seconds
lock.acquire(key, ttl, value, (e, r) => {
  // r === true;
});

// Renew a lock.
// It fails if the value is different.
lock.renew(key, ttl, value, (e, r) => {
  // r === true;
});

// Release a lock.
//  The value has to be passed to ensure another host doesn't release it.
lock.release(key, value, (e, r) => {
  //
});

// Does a lock exist?
lock.isLocked(key, (e, r) => {
  // Lock if r exists (this is the value of the lock)
});

Tests

  $ npm test

Author

Philmod <philippe.modard@gmail.com>

Keywords

FAQs

Last updated on 24 Nov 2016

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc