How to recreate Express Sessions

109 views
Skip to first unread message

Jordan

unread,
Sep 6, 2012, 1:38:44 PM9/6/12
to expre...@googlegroups.com
I'm using Redis as my sessionstore.  Given only the session id, I'd like to create a session object, so that I can have the session object whilst using session.io.  But most importantly, I want this session object to update Redis when I make a change to it (just like how request.session behaves).

Is this possible?  I haven't gotten it to work :(

_testSession: (sStore, sId) ->
console.log 'called _testSession with session id: ' + sId

sStore.get sId, (error, session) ->
expressSession = new Session 
sessionId: sId
sessionStore: sStore
, session
expressSession.foo = 17

console.log 'set expressSession.foo to: ' + expressSession.foo

setTimeout (()->
sStore.get sId, (error, session) ->
console.log 'foo = ' + session.foo
), 1000

This prints:

called _testSession with session id: SikwJgH5CnDPE64FhmvVSaS3.eqy5UHIqIWY3QM3EFlIrFGvjU2dvjhPBBcWSl7LiAqc
set expressSession.foo to: 17
foo = undefined


Thanks so much!

Jordan

unread,
Sep 6, 2012, 2:03:55 PM9/6/12
to expre...@googlegroups.com
Sorry, the code should read:

expressSession = new Session 
sessionID: sId
sessionStore: sStore
, session
expressSession.foo = 17

However, this still didn't change my output :(

Jordan

unread,
Sep 6, 2012, 2:38:48 PM9/6/12
to expre...@googlegroups.com
Hrrm, looks like I'm forced to call expressSession.save().
Reply all
Reply to author
Forward
0 new messages