Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including pull-redis-pubsub with all npm packages installed. Try it out:

var pullRedisPubsub = require("pull-redis-pubsub")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

pull-redis-pubsub v2.0.3

pull stream wrapper around redis pub sub

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()
)
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free