Created
May 7, 2018 15:44
-
-
Save liorkesos/5ba67198addf179c036c9515ab992ad9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var redis = require('redis'); | |
var app = require('http').createServer(); | |
io = require('socket.io').listen(app); | |
app.listen(8080); | |
io.sockets.on('connection', function (socket) { | |
const subscribe = redis.createClient(undefined, "redis.demos.cloud.linnovate.net") | |
const pub = redis.createClient(undefined, "redis.demos.cloud.linnovate.net") | |
/** | |
* Connect to redis channel and I trigger init event | |
*/ | |
socket.on("subscribe", function (channel) { | |
subscribe.subscribe(channel); | |
console.log('channel' + channel); | |
socket.emit("init", "woww"); | |
}); | |
/** | |
* Goodbye redis pub/sub! | |
*/ | |
socket.on('unsubscribe', function (obj) { | |
subscribe.unsubscribe(obj.channel); | |
}); | |
/* | |
* Redis use subcribe on for send new message in a channel | |
*/ | |
subscribe.on("message", function (channel, data) { | |
/* | |
* Socket.io use send function for trigger an event into default channel 'message' | |
*/ | |
socket.send(data); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment