npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

redis-event-emitter

v1.1.3

Published

Redis event emitter just as you've wanted.

Downloads

3

Readme

redis-event-emitter

A simple Redis-based EventEmitter.

Using this module you can emit any type of JS entities as argumets to many servers. For example you can use in in cluster applications as default event emitter via local redis or replicate your service to many servers and use this emitter as bus.

Installation

npm install redis-event-emitter

Usage

Lets make simple chat in console. Just start this code from test in two windows and type your message.

// create connection (you can use it in whole project, but store in file and export)
var redisEventEmitter = require('../index.js')({
    host: 'redishost.com'
});

process.stdin.setEncoding('utf8');

// Input data and press enter
process.stdin.on('readable', function() {
	var chunk = process.stdin.read();
	if (chunk !== null) {
		// On enter emit the message and the function
		// to execute on another instance of this test program
		redisEventEmitter.emit('mess', chunk, function(arg) {
			console.log("Display: " + arg);
		});
	}
});

process.stdin.on('end', function() {
  process.stdout.write('end');
});

redisEventEmitter.on('mess', function(message, callback) {
	// call function sent from far server
	callback(message);
});

Also you can emit with local variables

process.stdin.on('readable', function() {
	var chunk = process.stdin.read();
	if (chunk !== null) {
		// define val locals to avoid IDE displaying warnings
		var locals = {
			chunk: chunk
		};
		redisEventEmitter
		// apply your local variables before emit
		.apply(locals)
		.emit('mess2', function() {
			// Then use your variables as is on another server.
			// It will replace before sending to emitter
			// Valiable must be called locals. It is reserver word inside module
			console.log("Display: " + locals.chunk);
		});
	}
});

redisEventEmitter.on('mess2', function(callback) {
	// call function sent from far server with special params
	callback();
});

Caveats

When you push an function as argument you should understand that it will execute on another server and will not use current scope, so, don't use local variables to execute. Also, no sures for now that emit was executed. It realy works like typical push.

For serializing used https://github.com/yahoo/serialize-javascript module

API

Options:

  • host: '127.0.0.1', // Redis server host
  • port: 6379, // Redis server port
  • prefix: 'redis:emitter', // prefix
  • debug: false // console.log some data

Note: When connected to a Redis server, all events are routed through the server which may affect their latency locally as one would expect.

TODO

  • Promises to make sure that event emited.

Note on Patches/Pull Requests

  • They are very welcome.
  • Fork the project.
  • Make your feature addition or bug fix, preferably in a branch.
  • Send me a pull request.