Skip to content

Instantly share code, notes, and snippets.

@nxmad
Created December 12, 2017 09:56
Show Gist options
  • Save nxmad/e7f6eebb6addf25286642af27a40b4d3 to your computer and use it in GitHub Desktop.
Save nxmad/e7f6eebb6addf25286642af27a40b4d3 to your computer and use it in GitHub Desktop.
let app = require('http').createServer((req, res) => {
res.writeHead(200);
res.end('!@#');
})
let io = require('socket.io').listen(app)
app.listen(process.env.WS_PORT)
let Redis = require('redis').createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
});
const Handler = (channel, message) => {
message = JSON.parse(message);
let data = message.data;
let event = message.event.split('\\').reverse()[0];
Listener.fire(channel, event, data);
}
const Listener = {
fire(channel, event, data) {
if (this[channel].hasOwnProperty(event)) {
this[channel][event](data);
}
},
Channel: {
Event(data) {
}
},
}
Redis.on('message', Handler)
Redis.subscribe('Channel')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment