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

redis-message-queue

v1.0.2

Published

Redis Message Queue Middleware inspired by XadillaX

Downloads

10

Readme

Redis as Queue - Node.js SDK

Note: This is A node.js package for regarding redis as a message queue, npm repo: https://www.npmjs.com/package/redis-message-queue

Installation

$ npm install redis-message-queue

Usage

There are two kinds of queue - normal queue and unique queue.

Each value in unique queue is unique. If a new value that equals any value in the queue, you may choose to update or not.

First you should require this package:

var rmq = require("redis-message-queue");

Normal Queue

Create

var normalQueue = new rmq.NormalQueue(QUEUE_NAME, [...]);

Note: [...] is the option(s) to connect redis server. Refer to node-redis document.

Eg.

new rmq.NormalQueue(QUEUE_NAME, 6379, '127.0.0.1', {});
new rmq.NormalQueue(QUEUE_NAME, unix_socket, options);
...

Select

To Select a db :

normalQueue.select(db, function() {
    console.log("db select success");
});

Push

To push a message to your queue, you may use this function:

normalQueue.push("YOUR MESSAGE", function(err) {
    console.log(err);
});

Get

To get message(s) from your redis queue, you may use get function.

Get earlist one message
normalQueue.get(function(err, messages) {
    console.log(err);
    if(messages.length) console.log(messages[0]);
});
Get earlist N message(s)
// This call gets 10 earlist messages
normalQueue.get(10, function(err, messages) {
    console.log(err);
    for(var i = 0; i < messages.length; i++) console.log(messages[i]);
});
Get all message(s)
normalQueue.get(-1, function(err, messages) {
    console.log(err);
    for(var i = 0; i < messages.length; i++) console.log(messages[i]);
});

Remove

To remove message(s) from your redis queue, you may use removeAmount function.

Remove earlist one message
normalQueue.removeAmount(function(err) {
    console.log(err);
});
Remove earlist N message(s)
normalQueue.removeAmount(5, function(err) {
    console.log(err);
});
Remove all the message(s)
normalQueue.removeAmount(-1, function(err) {
    console.log(err);
});

Length

Get the length of current queue.

normalQueue.length(function(err, len) {
    console.log(len);
});

Unique Queue

Each message in unique queue is unique.

Create

var uniqueQueue = new rmq.UniqueQueue(QUEUE_NAME, [...]);

Note: [...] is the option(s) to connect redis server. Refer to node-redis document.

Eg.

new rmq.UniqueQueue(QUEUE_NAME, 6379, '127.0.0.1', {});
new rmq.UniqueQueue(QUEUE_NAME, unix_socket, options);
...

Select

To Select a db :

normalQueue.select(db, function() {
    console.log("db select success");
});

Push

Push a message to the queue.

Need update

This call will check if your message is existing. If existing, it will move the previous message to the end of queue. Otherwise, your message will be pushed at the end of queue.

uniqueQueue.push("YOUR_MESSAGE", true, function(err) {
    console.log(err);
});
Do not update

This call will check if your message is existing. If existing, it won't do anything. Otherwise, your message will be pushed at the end of queue.

uniqueQueue.push("YOUR_MESSAGE", function(err) {
    console.log(err);
});

// or you can do this

uniqueQueue.push("YOUR_MESSAGE", false, function(err) {
    console.log(err);
});

Get

Get first message
uniqueQueue.get(function(err, messages) {
    console.log(err);
    if(messages.length) {
        console.log(messages[0].message);
        console.log(messages[0].updatedAt);
    }
});
Get first N message(s)
uniqueQueue.get(3, function(err, messages) {
    console.log(err);
    for(var i = 0; i < messages.length; i++) {
        console.log(messages[i].message);
        console.log(messages[i].updatedAt);
    }
});
Get all the message(s)
uniqueQueue.get(-1, function(err, messages) {
    console.log(err);
    for(var i = 0; i < messages.length; i++) {
        console.log(messages[i].message);
        console.log(messages[i].updatedAt);
    }
});

Remove Amount

Refer to remove section in Normal Queue.

Remove Messages

Remove one or more certain message(s) in the queue.

uniqueQueue.get(10, function(err, messages) {
    for(var i = 0; i < 5; i++) messages.shift();

    // Remove Messages
    uniqueQueue.removeMessages(messages, function(err, removeCount, notRemovedMessages) {
        console.log(err);
        console.log(removeCount);
        for(var i = 0; i < notRemovedMessages.length; i++) console.log(notRemovedMessages[i].message);
    });
});

Length

Refer to length section in Normal Queue.

Common Functions

Delete Queue

Delete this queue key and values in redis.

uniqueQueue.deleteQueue(function() {});
normalQueue.deleteQueue(function() {});

Destroy Queue Object

Let the queue object disconnect from redis server and let this instance can't do any other thing any more.

uniqueQueue.destroy();
normalQueue.destroy();

Contribute

You're welcome to pull requests!