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 = client = Redison; client;
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 = nrClient = node_redis; var redisonClient = ;
Subscribe with Event Map
Setting callbacks of redis subscriber events for every channel/pattern by hashmap.
Precondition
var Redison = client = Redison;
Start/Stop listener
startListener([eventNames])
This activates listeners of redis subscriber events specified in [eventNames]
.
client;
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;
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 { console; } { console; } { console; } subChannel2: { console; } { console; } { console; }
Pattern subscriber
setPsub(psubMap)
Setting up redis pattern subscriber with callbacks defined in psubMap
.
client;
The psubMap
is written as follows:
var psubMap = //patterns "pattern*": //event:callback { console; } { console; } { console; } "pat*ern": { console; } { console; } { console; }
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;
Unsubscribe/Punsubscribe as Quit
client;
client;
Unsubscribe/Punsubscribe as Pause
client;
client;
LICENSE
MIT