pull-redis-pubsub
v2.0.3
Published
pull stream wrapper around redis pub sub
Downloads
24
Readme
pull-redis-pubsub
Simple wrapper to get redis pub sub channels as a pull stream.
subscriber
The subscriber is a pull stream source that will emit new messages over time.
publisher
The publisher is a pull stream sink that you can pipe new messages too.
install
npm install pull-redis-pubsub
example
Publisher
var redis_pub = require('pull-redis-pubsub').pub;
var pushable = require('pull-pushable')
var pull = require('pull-stream')
function publisher () {
if (! (this instanceof publisher)) return new publisher ();
this.buffer = new pushable;
var self = this;
this.emit = function (data) {
self.buffer.push(JSON.stringify(data));
}
pull(
this.buffer,
redis_pub('cool_channel')
)
}
var pub = publisher ()
setInterval(function () {
pub.emit({
demo: Math.random() // important data
})
}, 1000)
Subscriber
var redis_sub = require('pull-redis-pubsub').sub;
var pull = require('pull-stream')
pull(
redis_sub('cool_channel'),
pull.log()
)