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

redison

v0.0.9

Published

Redis subscribe event mapper

Downloads

3

Readme

#About Redis subscribe event mapper

#Dependencies

  • redis

#Install

##From Github

$ git clone [email protected]:YoshiyukiKato/Redison.git
$ cd Redison && npm install

##From npm

$ npm install redison

#Usage

##Overview Redison provides simple method for setting callbacks for events of Redis subscriber by hashmap.

var Redison = require("redison"),
    client = Redison.redisonize().startListener();

client.setSub({
    subChannel1:{
        subscribe:function(channel,count){
            console.log("Subscribing " + channel + " :: Now we subscribe " + count + " channels");
        },
        message:function(channel,message){
            console.log(message);
        }
    }
});

Redison extends node_redis without overriding any method. You can use Redison client same as node_redis client.

In case of setting detail prameter of redis connection in node_redis client, you can decorate the node_redis client by redisonize method.

var node_redis = require("redis"),
    nrClient = node_redis.createClient(port, host, options);
    
var redisonClient = require("redison").redisonize(nrClient);

##Subscribe with Event Map Setting callbacks of redis subscriber events for every channel/pattern by hashmap.

Precondition

var Redison = require("redison"),
    client = Redison.redisonize();

###Start/Stop listener

####startListener([eventNames])

This activates listeners of redis subscriber events specified in [eventNames].

client.startListener("subscribe","message");

In case of invokation with no arguments, startListener activates event listeners of all redis subscriber events: subscribe, message, unsubscribe, psubscribe, pmessage, punsubscribe.

####stoplistener([eventNames])

This removes listeners of redis subscriber events specified in [eventNames].

client.stopListener("subscribe","message");

In case of invokation with no arguments, stopListener removes event listeners of all redis subscriber events: subscribe, message, unsubscribe, psubscribe, pmessage, punsubscribe.

###Common subscriber

####setSub(subMap) Setting up common redis subscriber with callbacks defined in subMap.

client.setSub(subMap);

The subMap is written as follows:

var subMap = {
    //channels name
    subChannel1:{
        //event:callback
        subscribe:function(channel,count){
            console.log("Subscribing " + channel + " :: Now we subscribe " + count + " channels");
        },
        message:function(channel,message){
            console.log(message);
        },
        unsubscribe:function(channel,count){
            console.log("Unsubscribing " + channel + " :: Now we subscribe " + count + " channels");
        }
    },
    subChannel2:{
        subscribe:function(channel,count){
            console.log("callback");
        },
        message:function(channel,message){
            console.log("I got a message :: " + message);
        },
        unsubscribe:function(channel, count){
            console.log("See you " + channel);
        }
    }
}

###Pattern subscriber ####setPsub(psubMap) Setting up redis pattern subscriber with callbacks defined in psubMap.

client.setPsub(psubMap);

The psubMap is written as follows:

var psubMap = {
    //patterns
    "pattern*":{
        //event:callback
        subscribe:function(channel,count){
            console.log("Subscribing " + channel + " :: Now we subscribe " + count + " channels");
        },
        message:function(pattern,channel,message){
            console.log(pattern + " :: " + channel + " :: " +message);
        },
        unsubscribe:function(channel,count){
            console.log("Unsubscribing " + channel + " :: Now we subscribe " + count + " channels");
        }
    },
    "pat*ern":{
        subscribe:function(channel,count){
            console.log("callback");
        },
        message:function(pattern,channel,message){
            console.log("I got a message from" + channel + "caught by" + pattern + ":: " + message);
        },
        unsubscribe:function(channel, count){
            console.log("See you " + channel);
        }
    }
}

##Unsubscribe with State Unsubscribing a specific channel/pattern with a state. The state allows you to choose whether delete callback setted by Event Map or not. stateUnsub/statePunsub method provides two kinds of unsubscription: quit and pause. The quit deletes callback, the pause do not.

client.stateUnsub(channel,quitState);

###Unsubscribe/Punsubscribe as Quit

client.stateUnsub(channel,true);
client.statePunsub(pattern,true);

###Unsubscribe/Punsubscribe as Pause

client.stateUnsub(channel,false);
client.statePunsub(pattern,false);

##LICENSE MIT