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 🙏

© 2024 – Pkg Stats / Ryan Hefner

pushpull

v2.1.8

Published

Push/Pull pattern using Redis lists as backend

Downloads

2

Readme

Build Status Dependency Status devDependency Status

Push/Pull

Implement a Push/Pull mecanism using Redis as backend. This pattern is typically used to handle pool of workers.

Installation

npm install --save pushpull

If you don't already use Redis and still use npm ≤ 2.x, you'll have to install redis too:

npm install --save redis

You may want to install hiredis to, whenever possible:

npm install --save-optional hiredis

Usage

Look at (and run) sample.js for a working example.

// Worker

var Pull = require("./").Pull;

var worker = new Pull(options);
worker.on("data", function (data) {
  // do something with data
});

// Sender

var Push = require("./").Push;

var sender = new Push(options);
sender.emit("data", {"some": "data"});

Pull API

Pull instances are valid readable streams (object mode).

  • new Pull(options): constructor, see Options below
  • data event: emitted when data has been pulled from queue
  • error event: emitter when an error occurs (seriously)
  • pause(): stop querying for more data
    • IMPORTANT: this method cannot interrupt current fetch, which means one job can be pulled before puller is actually paused. This data will be buffered and emitted again as soon as you call resume().
  • resume(): quit pause
  • end(): close the underlying Redis client, which obviously prevents any further query

Push API

Push instances are valid writable streams (object mode).

  • new Push(options): constructor, see Options below
  • write(data): emit this event to push a job to queue
  • pushed event: emitted when data has been pushed successfully
  • error event: emitter when an error occurs (seriously)
  • end(): close the underlying Redis client, which obviously prevents any further query

Options

  • queue (mandatory): queue name, to be shared between worker(s) and sender(s)
    • Note: a Redis list with this name will be created. No decoration added, if you want to ensure unicity of the name, it's up to you to add prefix or suffix
  • timeout (Pull only, default = 30 seconds): timeout between two BLPOP commands, the lower the value, the higher the chance not to grab data when calling pause()
  • client: the Redis client to be used
    • IMPORTANT: a Pull instance will run BLPOP commands, which BLOCK the client. It's highly advised to use a unique client for each puller.
  • host (default = localhost): Redis host (if client is not set)
  • port (default = 6379): Redis port (if client is not set)
  • database: Redis database to select once connected, if set

Internals

In both Push and Pull instances, you have access to some semi-privates:

  • _redisClient is the internal Redis client instance
  • _queue is the name of the queue
    • Note: changing its value will have expected effect, although you should only do it if you know what you're doing

Why documenting those internals? Because I use them in a project using this module, and I want to make sure those features don't get away with no warning.