Node.js wrapper for Redis' Publish - Subscribe messageing pattern. Supports message filtering and more.
Tested with node 0.10.x
##Changelog
v2.0.0
- removed chaining
v1.1.2
- removed pattern from final message object
v1.1.1
- simple mode for using raw redis Pub/Sub optionally
v1.1.0
- added
channel
andpattern
to the message object, for easier querying.
v1.0.2
- Fix - channel was not passed by the event callback
- TODO: add more proper tests and perform benchmarking
v1.0.1
- added channel and pattern info to be trnsfered along with data as extra parameters
v1.0.0
- correct version numbering and some fixes
v0.1.6
- arrays can now be processed with queries
v0.1.5 Notable changes since v0.1.0
- New way to create instances
- The .on method takes different parameters
- Filtering messages is possible using mongoDB-like queries or regular expressions
v0.1.0 Initial forking release
##Install
$ npm install redis.pubsub --save
Test
$ make test
var redisPubSub = require('redis.pubsub')([config [, options]])
- config:
{ port || 6379, host || 'localhost', pass }
.port
,host
andpassword
to connect to a Redis server. - options: Accepts all options for Redis'
createClient()
method.
// in Simple mode
var PubSub = new redisPubSub('simple'))
// or Query mode
var PubSub = new redisPubSub()
PubSub.emit(channel, message)
- channel: Name of a publishing channel, e. g.
drain
ordrain.pipe
| defaults to*
- message: Object to be published. Strings do not apply!.
####in Query mode (default)
var sub = PubSub.on(query, filter, callback = function (data, channel, pattern) {
// process your data here
})
- query: query to filter messages. Supports mongoDB-like queries and regular expressions.
- filter: filter returned data by displaying only selected keys
- callback: function to process returned
data
sent on a specificchannel
and captured by a listenerpattern
####in Simple mode
var sub = PubSub.on(channel, callback = function (data, channel, pattern) {
// process your data here
})
- channel: channel name or pattern e. g.
drain.pipe
ordrain.*
. - callback: function to process returned
data
sent on a specificchannel
and captured by a listenerpattern
#####Function returns reference to subscription.
You can unsubscribe by:
// calling a reference object from when subscribing
sub([callback])
// or using the reference as a param (single or multiple as an array)
PubSub.off(target[, callback])
- target: reference to a subscription or an array of subscription objects
- callback: optional
PubSub.clear([callback])
- callback: optional
Method removes all subscriptions, clears the filter queue and removes the Redis client.
PubSub.cleanUp([callback])
- callback: optional
##Example
// TODO: write this
##License
Copyright (C) 2013 Paweł Waleczek
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.