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

zk-redis-queue

v0.1.10

Published

Truly distributed and parallel parallel queue on top of redis and zookeeper without SPoF.

Downloads

42

Readme

zk-redis-queue

Reliable queue that duplicate items among redis servers and synchronize with zookeeper. Use if you don't want to loose your data and don't mind if some items can be processed more than 1 time if redis fails.

Advantages

  • No single point of failure (SPoF): zookeeper is distributed, redis data is duplicated.
  • Losing data is impossible if you have at least 1 redis server alive.
  • Processing can be paralleled horizontally if you want to process faster.

Disadvantages

  • Not strongly ordered.
  • Duplicate items are the same — you need to add timestamp or something to make them different.
  • Can process items more than 1 time if redis has failed and returned with non-empty set.

Installation

npm install zk-redis-queue

Usage

You may be interested in test/test.js for now. In this example you'll need 2 redis servers on 127.0.0.1:6379 and 127.0.0.1:6380. We'll use shared zk instance so performance will be poor, please start your own cluster for production use.

var Redis    = require("redis"),
    Queue    = require("../index"),
    ZK       = require("zkjs"),
    zk       = new ZK({hosts: ["api.yongwo.de:2181"], root: "/pew-pew", timeout: 2000}),
    redisOne = Redis.createClient(6379, "127.0.0.1", {retry_max_delay: 1000}),
    redisTwo = Redis.createClient(6380, "127.0.0.1", {retry_max_delay: 1000}),
    queue    = new Queue([redisOne, redisTwo], zk, "woo"); // "woo" is a queue key

// error event is triggered for recoverable errors,
// if error is unrecoverable, you'll receive error in callback
queue.on("error", function(error) {
    console.log("Got warning", error);
});

// we are ready to start
queue.on("ready", function() {
    // push item to queue
    queue.push("pew", function(error) {
        if (error) {
            // push failed on every redis server
            throw error;
        }
    });

    // let's try to get something for 5 times (second argument)
    queue.pop(function(error, item, remove) {
        if (error) {
            // no redis servers are alive
            // or zookeeper is down
            // damn!
            throw error;
        }

        if (item) {
            // we got item and it's locked for us!
            console.log("Look what I've got:", item);

            // remove item after all work is done
            remove(function() {
                // no error if everything is down,
                // "error" event will be emitter
                // and item can be processed by another worker
                console.log("Item removed!");
            });
        }
    }, 5);
});

Implementation

Queue consists of 2 elements: zookeeper pool (synchronization to make parallel processing possible) and redis pool (data storage). Redis servers are completely independent. We suggest you to have at least 3 redis servers on different physical servers.

Authors