Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ienderli's avatar

Add To Redis Session From Node?

So I am using node, redis, and laravel. At the moment I can connect from browser, use laravels session cookie to get and parse the session stored in redis. but I cannot figure out how to store something in the session, from node, in the same format that laravel does . I am guessing I am not re-serializing my session object correctly in node, but I am lost.

After I get the cookies from the socket handshake, i decrypt them, and from there get session

function findSessionById(id) {
    return this.redis.get(id, function(err, session) {
        session = PHPUnserialize.unserialize( PHPUnserialize.unserialize( session ) );
        session.id = id;

        return new SessionStore(this.redis, session);
    }.bind(this));
}

Function above returns a promise that will have a session in it like below, and then I pass it in to a session store object that will hopefully be responsible for persisting new session data.

// Session Object From Redis Db
{
    _token: 'aveYTOKENrP85txSkTOKENmPcXHU1C9pSsSF6FKH',
    _previous: { url: 'http://laravel.dev' },
    _sf2_meta: { u: 1456424284, c: 1456424284, l: '0' },
    flash: { old: {}, new: {} }
}

Anybody know how to add to the session object right above and then save it in redis?

0 likes
0 replies

Please or to participate in this conversation.