npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@bitfinex/bfx-facs-redis-lock

v0.0.2

Published

Bitfinex Redis Lock Facility

Readme

bfx-facs-redis-lock

Development

git clone https://github.com/bitfinexcom/bfx-facs-redis-lock
cd bfx-facs-redis-lock
git remote add upstream https://github.com/bitfinexcom/bfx-facs-base

Usage

In your service, run:

npm i --save https://github.com/bitfinexcom/bfx-facs-redis-lock

Integration

RedisLock is a class that extends from Facility, the main class in bfx-facs-base.

This Facility encapsulates the node-redlock libary.

Redlock can use node redis, ioredis redis library to keep its client connections.


// Instance an object
const RedLockFac = require('bfx-facs-redis-lock')
// Create a redis client (Redlock can use node redis, ioredis or any other compatible redis library to keep its client connections.)
const redisClient = require('redis').createClient(6379, 'redis1.example.com');
// Pass redis client to redlock
const redLockFac = new RedLockFac (caller, {
    redis_client : redisClient
}, ctx)

// Within a worker constructor

this.setInitFacs([
    // Start a Redis client First.
    ['fac', 'bfx-facs-redis', '0', '0',{}, -4],
    
    ['fac', 'bfx-facs-redis-lock', '0', '0', () => {
        // Pass a Redis client to Redis Lock Fac
        return {
            redis_client: this.redis_0.cli_rw
        }
    }, -3]
])

Main functions

RedLockFac.lock.lock(resource, ttl, ?callback) => Promise<Lock>

  • resource (string) resource to be locked
  • ttl (number) time in ms until the lock expires
  • callback (function) callback returning:
    • err (Error)
    • lock (Lock)

RedLockFac.lock.unlock(lock, ?callback) => Promise

  • lock (Lock) lock to be released
  • callback (function) callback returning:
    • err (Error)

RedLockFac.lock.extend(lock, ttl, ?callback) => Promise<Lock>

  • lock (Lock) lock to be extended
  • ttl (number) time in ms to extend the lock's expiration
  • callback (function) callback returning:
    • err (Error)
    • lock (Lock)

RedLockFac.lock.disposer(resource, ttl, ?unlockErrorHandler)

  • resource (string) resource to be locked
  • ttl (number) time in ms to extend the lock's expiration
  • callback (function) error handler called with:
    • err (Error)

RedLockFac.lock.quit(?callback) => Promise<*[]>

  • callback (function) error handler called with:
    • err (Error)
    • *[] results of calling .quit() on each client

Lock.unlock(?callback) => Promise

  • callback (function) callback returning:
    • err (Error)

Lock.extend(ttl, ?callback) => Promise<Lock>

  • ttl (number) time from now in ms to set as the lock's new expiration
  • callback (function) callback returning:
    • err (Error)
    • lock (Lock)

Usage

Locking & Unlocking (Callbacks)


// the string identifier for the resource you want to lock
var resource = 'locks:account:322456';

// the maximum amount of time you want the resource locked,
// keeping in mind that you can extend the lock up until
// the point when it expires
var ttl = 1000;

redlock.lock(resource, ttl, function(err, lock) {

	// we failed to lock the resource
	if(err) {
		// ...
	}

	// we have the lock
	else {


		// ...do something here...


		// unlock your resource when you are done
		lock.unlock(function(err) {
			// we weren't able to reach redis; your lock will eventually
			// expire, but you probably want to log this error
			console.error(err);
		});
	}
});

Locking and Extending (Promises)

redlock.lock('locks:account:322456', 1000).then(function(lock) {

	// ...do something here...

	// if you need more time, you can continue to extend
	// the lock as long as you never let it expire

	// this will extend the lock so that it expires
	// approximitely 1s from when `extend` is called
	return lock.extend(1000).then(function(lock){

		// ...do something here...

		// unlock your resource when you are done
		return lock.unlock()
		.catch(function(err) {
			// we weren't able to reach redis; your lock will eventually
			// expire, but you probably want to log this error
			console.error(err);
		});
	});
});