Skip to content

Instantly share code, notes, and snippets.

@gate3
Created September 13, 2019 15:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gate3/f2da2986aef2bd740da72627ad89bae6 to your computer and use it in GitHub Desktop.
Save gate3/f2da2986aef2bd740da72627ad89bae6 to your computer and use it in GitHub Desktop.
// Note i skipped a lot of steps here like starting a server etc
require('dotenv').config()
const redis = require('redis')
const sub = redis.createClient();
const cp = require('child_process');
const glob = require('glob');
glob('!(node_modules)/**/*.worker.js', function (er, files) { // Ignore all workers in node_modules and use only those defined within my app
for (let f of files) {
cp.fork(`${__dirname}/${f}`);
}
});
// Subscribe to the redis channel and anytime an event is fired get it and send to the client
const type = `channel:user` // Let listen on the user channel for example
sub.subscribe(type)
sub.on('message', function(channel, message){
// Send a socketio event and listen on the client
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment