Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pwaleczek committed Sep 23, 2013
1 parent f7b9fda commit de2f73b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Supports message filtering and more.
##Changelog

###v1.0.0:
* correct version numbering and some fixes

###v0.1.6:
* arrays can now be processed with queries

Expand Down Expand Up @@ -62,8 +65,8 @@ Supports message filtering and more.
PubSub.emit(channel, message)
```

* __channel__: Name of a publishing channel, e. g. `drain` or `drain.pipe` | defaults to '*'
* __message__: Object to be published. Goes through `JSON.stringify`.
* __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
Expand All @@ -88,16 +91,16 @@ You can unsubscribe by:
```javascript
// calling a reference object from when subscribing
sub([callback])
// or
// using the reference as a param (single or multiple as an array)

// 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
### Clear all queue filters aka reset

```javascript
PubSub.clear([callback])
Expand Down
23 changes: 16 additions & 7 deletions lib/redis-pub-sub.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function setup(_config, _options) {
return PubSub
}


var PubSub = function () {
this.query = Query.create()

Expand All @@ -67,7 +68,13 @@ var PubSub = function () {

// Create a Subscriber instance
this.Sub = function (channel, callback) {
callback = callback ||function () {}

if (channel instanceof Function) {
callback = channel
channel = null
} else {
callback = callback || function () {}
}
channel = channel || '*'

var _this = this
Expand All @@ -77,8 +84,6 @@ var PubSub = function () {
_this.query.check(JSON.parse(message))
})

this._sub.psubscribe(channel, callback)

if (this._channels)
this._channels.push(channel)
else
Expand All @@ -90,14 +95,15 @@ var PubSub = function () {
this.off = off
this.clear = clear

this._sub.psubscribe(channel, callback)

return this
}

if (this instanceof PubSub) {
if (this instanceof PubSub)
return this.PubSub
} else {
else
return new PubSub()
}
}


Expand All @@ -113,7 +119,10 @@ var emit = function(channel, message) {
throw new Error('Can\'t publish without a client!')
return
}
this._pub.publish(channel, JSON.stringify(message))
if (typeof message !== 'string')
message = JSON.stringify(message)

this._pub.publish(channel, message)

return this
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redis.pubsub",
"version": "0.1.6",
"version": "1.0.0",
"description": "A Redis Publish-Subscribe wrapper, with message queries",
"main": "index",
"scripts": {
Expand Down

0 comments on commit de2f73b

Please sign in to comment.