Code Monkey home page Code Monkey logo

node-redis-event's Introduction

node-redis-event

Distributed node.js event emitter based on redis pub/sub.

Supports channels (sort of namespaces). This code is heavily used 24x7 on a thousand-servers cluster, so it is production ready.

SYNOPSIS

var RedisEvent = require('redis-event');

var ev = new RedisEvent('redis-host', ['updates', 'stats']);
ev.on('ready', function() {
	ev.on('updates:server', function(data) {
		console.log("Host %s updated to %d", data.hostname, data.count);
	});

	ev.pub('updates:test', { 
		launchedAt: new Date() 
	});

	ev.pub('stats:date', { 
		now: new Date() 
	});

	ev.on('updates:shutdown', function(data) {
		ev.quit();
	});
});

Installation

npm install redis-event

API

new RedisEvent(hostname, [channel, channel, channel...])

Initialise object.

Arguments

  • hostname - redis hostname to connect to
  • channel - name(s) of the redis pub/sub channel(s) to subscribe to

redisEvent.pub(eventName, payload)

Emit network event.

Arguments

  • eventName - event name in form of channel:name, eg. server:stats
  • payload - optional JS object to add to the event. Must be serializable to JSON

redisEvent.on(eventName, function(payload))

Subscribe to network event. Special case: ready event (see below).

Arguments

  • eventName - event name in form of channel:name, eg. server:stats
  • payload - optional JS object that was added to event

redisEvent.on('ready')

This event is emitted when redis-event has successfully connected to both redis sub and pub channels. You will want to emit events only after this event is fired. If also can be fired multiple times in case there was a reconnect.

redisEvent.quit()

Disconnect from redis. This is actually useful to quit node application.

TODO

  • Encryption

node-redis-event's People

Contributors

bratchenko avatar egorfine avatar kinke avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.