Socket
Socket
Sign inDemoInstall

redis-event

Package Overview
Dependencies
4
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    redis-event

Distributed pub/sub events based on redis


Version published
Maintainers
1
Install size
286 kB
Created

Readme

Source

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

Keywords

FAQs

Last updated on 02 Aug 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc