Sunday 21 May 2017

socket.io can server using redis stored session with mysql query after user disconnected?

I using passport and socket.io with redis to get session when I connect to server or disconnect and I get that successfully on my terminal console.log but I want to know did I need any something also to be sure the server will get the right session even if the user lost electricity suddenly ? I tried it on my local host and that's worked very good and database updated did that will be any difference when I run this code on public host on how it work ? and how the server get session stored even after disconnection ?

io.sockets.on('connection', module.exports = function(socket){


    connections.push(socket);
    //app.use(session);

    console.log('connected: %s socket connected session',socket.request.user.email ,connections.length);
    connection.query("UPDATE users SET TESTON= '1111' WHERE email='"+socket.request.user.email+"'");


    //discon
socket.on('disconnect',function(data){
    users.splice(users.indexOf(socket.username),1);
    updateUsernames();
    connections.splice(connections.indexOf(socket), 1);
    console.log('Disconnected: %s sockets connecte',socket.request.user.email, connections.length);
    connection.query("UPDATE users SET TESTON= '2222' WHERE email='"+socket.request.user.email+"'");



  });



via dark night

No comments:

Post a Comment