0.0.9 • Published 11 years ago

redison v0.0.9

Weekly downloads
4
License
MIT
Repository
github
Last release
11 years ago

#About Redis subscribe event mapper

#Dependencies

  • redis

#Install

##From Github

$ git clone git@github.com: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

0.0.9

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago

0.3.4

11 years ago

0.3.2

11 years ago

0.3.1

11 years ago

0.3.0

11 years ago

0.0.0

11 years ago