2.0.3 • Published 7 years ago

pull-redis-pubsub v2.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

pull-redis-pubsub

Build Status

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()
)
2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago