Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-redis-warlock

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-redis-warlock

Battle-hardened distributed locking using redis

  • 0.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
38K
increased by11.59%
Maintainers
1
Weekly downloads
 
Created
Source

warlock

Battle-hardened distributed locking using redis.

Requirements

  • node-redis compatible with v0.10
  • Redis v2.6 or above

Install

npm install node-redis-warlock

Usage


var Warlock = require('node-redis-warlock');
var redis = require('redis');

// Establish a redis client and pass it to warlock
var redis = redis.createClient();
var warlock = Warlock(redis);

// Set a lock
var key = 'test-lock';
var ttl = 10000;

warlock.lock(key, ttl, function(err, unlock){
  if (err) {
    // Something went wrong and we weren't able to set a lock
    return;
  }

  if (typeof unlock === 'function') {
    // If the lock is set successfully by this process, an unlock function is passed to our callback.
    // Do the work that required lock protection, and then unlock() when finished...
    //
    // do stuff...
    //
    unlock();
  } else {
    // Otherwise, the lock was not established by us so we must decide what to do
    // Perhaps wait a bit & retry...
  }
});

ProTips

  • Warlock uses Lua scripting to achieve transactional locking on Redis v2.6.0 upwards. If you're running Redis v2.6.12 or above you could use the additional PX and NX arguments for the SET operation as an alternative.
  • Read my Distributed locks using Redis article and Redis' author's A proposal for more reliable locks using Redis to learn more about the theory of distributed locks using Redis.

Keywords

FAQs

Package last updated on 19 Jun 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

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc