Skip to content

pwaleczek/redis.pubsub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Redis.PubSub Build Status NPM version Code Climate

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 and pattern 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

Usage

Include in the project

  var redisPubSub = require('redis.pubsub')([config [, options]])
  • config: { port || 6379, host || 'localhost', pass }. port, host and password to connect to a Redis server.
  • options: Accepts all options for Redis' createClient() method.

Create an instance

  // in Simple mode
  var PubSub = new redisPubSub('simple'))

  // or Query mode
  var PubSub = new redisPubSub()

Set up an emiter

  PubSub.emit(channel, message)
  • channel: Name of a publishing channel, e. g. drain or drain.pipe | defaults to *
  • message: Object to be published. Strings do not apply!.

Set up a listener

####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 specific channel and captured by a listener pattern

####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 or drain.*.
  • callback: function to process returned data sent on a specific channel and captured by a listener pattern

#####Function returns reference to subscription.


Disable a listener

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

Clear all queue filters aka reset

  PubSub.clear([callback])
  • callback: optional

Destroy the instance and Redis client

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.

About

node.js wrapper for Redis's Publish - Subscribe events

Resources

License

Stars

Watchers

Forks

Packages

No packages published