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 🙏

© 2025 – Pkg Stats / Ryan Hefner

simple-redis-safe-work-queue

v3.1.1

Published

Redis-based simple and safe work queue

Readme

simple-redis-safe-work-queue

Build Status

Gitter chat

A work queue for Node.js producers and consumers that uses Redis.

Client

Example of a client producing work:

var Queue = require('simple-redis-safe-work-queue');

client = Queue.client('send-email');
client.push({to: '[email protected]', subject: 'hey there', body: 'yo'});

or, with a callback for when the work is pushed:

client.push({to: '[email protected]', subject: 'hey there', body: 'yo'}, function(err) {
  if (err) console.error('Error when pushing work into the queue: ', err.stack);
});

You can also provide some options for the work item you're pushing:

var options = {
  timeout: 120e3 // 120 seconds
};

client.push({to: '[email protected]', subject: 'hey there', body: 'yo'}, options, function(err) {
  if (err) console.error('Error when pushing work into the queue: ', err.stack);
});

Client options:

Client also accepts options as second argument in constructor:

  • port: redis port, defaults to 6379
  • host: redis host name, defaults to "127.0.0.1"
  • password: redis password, defaults to undefined
  • redisOptions: additional redis options, defaults to undefined
  • defaultTimeout: the default worker timeout, in miliseconds. defaults to 60000 (60 seconds)

Client events:

Client emmits the following events:

  • emit('before push', work) - before work is pushed
  • emit('after push', work) - after work is successfully pushed
  • emit('error', err) - when a push error happens and a callback wasn't provided

Worker

Example of a worker consuming work:

var Queue = require('simple-redis-safe-work-queue');

worker = Queue.worker('send-email', workFunction);

function workFunction(email, cb) {
  sendEmail(email, function(err) {
    if (err) cb(err);
    else {
      console.log('email send successfully, calling back with no errors');
      cb();
    }
  });
}

Worker options:

You can pass some options on the third argument of the worker constructor:

  • port: redis port (defaults to 6379)
  • host: redis host (defaults to "127.0.0.1")
  • password: redis password
  • redisOptions: any option allowed by the redis client, defaults to undefined
  • maxConcurrency: the maximum pending work units. defaults to 10.
  • maxRetries: the maximum number of retries when a work unit errors. defaults to 10.
  • popTimeout: the worker pop timeout, after which it retries, in seconds. Defaults to 3 seconds.
  • runTimeoutWatchdog: run a timeout watchdog, defaults to true
  • runStalledWatchdog: run a stalled watchdog, defaults to true
  • autoListen: worker listens automatically (otherwise you must call .listen() or .fetch() when ready for the next message), defaults to true

The .fetch() method is a non-long-polling version of .listen(), useful when you want to get a null response if there are no messages, rather than waiting for one to be pushed. If you're using autoListen: false then you probably want to use .fetch().

Worker Events:

A worker emits the following events:

  • emit('ready'): when redis client is ready
  • emit('listening'): when listening for work
  • emit('worker error', err): when a worker error occurs
  • emit('work done', work): when a worker finishes a piece of work
  • emit('repush', payload): when a work unit is being repushed after failure
  • emit('max retries', lastError, payload): when the maximum retries has been reached

Requirements

Redis 2.6 or greater, with Lua scripting enabled.

Testing

Clone this repo, enter the repo directory, start a redis server and run:

$ npm test

License

MIT