Coder Social home page Coder Social logo

redis-events's Introduction

Redis Events

Inter-process/inter-system event emitter

Redis event emitter is built against the node.js Event Emitter API. It helps scale out code built using event emitters without having to change any app related code (well, a signle line of code!). Simply require redis-events instead of events.

It supports all the methods exposed by Node's built-in event emitters.

Usage

Example

var EventEmitter = require('redis-events').EventEmitter;

// the following code stays exactly the same
var emitter = new EventEmitter();

emitter.on('msg', function(arg1, arg2, arg3) {});

emitter.emit('msg', 1, 2, 3);

Options

An options object can be passed to the event emitter to provide Redis connection options. Supported options include port, host and auth. These are passed straight to the node-redis module.

Example

var emitter = new EventEmitter({
	port: 12000,
	host: 'db-server.company.local'
});

Global defaults

To further assist the transition from using built-in event emitters to redis event emitters, the redis database options can be set globally once by editing the global defaults hash. Be careful when using this as it will apply these defaults application wide.

Example
// emitter-defaults.js

var EventEmitter = require('redis-events').EventEmitter;

// change global defaults
	// make sure this file is require'd before any other file that relies on event emitters
EventEmitter.defaults = {
	port: 12000,
	host: 'db-server.company.local'
};
// app.js

// nothing changes in this file except for the required module

var EventEmitter = require('redis-events').EventEmitter;

var emitter = new EventEmitter();

Gotchas

The data structure of arguments passed needs to be supported by both JSON.stringify and Redis. So, be careful if using objects such as Errors, Functions or arguments as event args.

Changelog

v0.0.2

  • Fix for issue #2
  • Added tests

v0.0.1

  • Initial commit

redis-events's People

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.