Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Nodejs Server ---------------------------
- var io = require('socket.io').listen(3000);
- var redis = require('redis');
- var $clients = {};
- var $notifySubscribe = redis.createClient();
- var $loginUserSubscribe = redis.createClient();
- $notifySubscribe.subscribe('notify');
- $loginUserSubscribe.subscribe('loginUser');
- $notifySubscribe.on('message', function($channel, $message) {
- var $data = JSON.parse($message);
- if($data.userId in $clients){
- $clients[$data.userId].emit('updateNotifications', '+1');
- }
- });
- io.sockets.on('connection', function(socket) {
- $loginUserSubscribe.on('message', function($channel, $message){
- var $data = JSON.parse($message);
- if(!($data.userId in $clients)){
- $clients[$data.userId] = socket;
- }
- });
- });
- //Client ----------------------------------
- socketIo.on('updateNotifications', function($count){
- alert($count);
- });
- //Php Server ------------------------------
- $data = array('userId' => 20584, 'username' => 'mohammadsaleh');
- $this->__redis->publish("notify", json_encode($data));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement