-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read/write a value in session #2
Comments
not sure I got it - can you paste your code to give more context? |
Basically it's your code in coffeescript and I'd like to increment counter in session every time the client send the ping event (example). I've also look at express session example, but I'm not sure if it works in the same way with socket.io https://github.com/visionmedia/express/blob/master/examples/session/redis.js
|
yea you should use session and not sessionStore for that case. if session is null, err should be present and tell what's the problem. seems like you're missing some config. can you paste your complete code? which version of express and socket.io are you using? |
And this is the full test code I'm using:
|
ok I can reproduce it with memory store by faking a wrong session key; seems like redis store uses a different session key from connect/express default. what doesn't make sense is that you ran into the same with memory store, right? can you paste your output of socket.handshake in the server so we can track your session key? then you will need to pass it to sessionSocket as the last optional parameter (see readme). |
Yieeeh!!!! Thanks for helping me in the debug. Now it almost work but it seems the MemoryStore is used even if I specified redis # like below
# ..
socket.on "ping", (data) ->
if session.counter
++session.counter
else
session.counter=1
console.log '@sess2: '+JSON.stringify session
OUTPUT @handshake: {"headers":{"host":"0.0.0.0:3000","connection":"keep-alive","cache-control":"max-age=0","user-agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.64 Safari/537.4","accept":"/","referer":"http://0.0.0.0:3000/","accept-encoding":"gzip,deflate,sdch","accept-language":"it-IT,it;q=0.8,en-US;q=0.6,en;q=0.4","accept-charset":"UTF-8,*;q=0.5","cookie":"connect.sid=s%3Ao0wxRV%2BykXOIxT3FNwsIG9OX.CpuI3xm%2BR3ZeFQKkOMRoP38K12yPMAQVoMXiEv%2BThds"},"address":{"address":"127.0.0.1","port":55613},"time":"Sat Sep 22 2012 11:11:21 GMT+0200 (CEST)","query":{"t":"1348305081311"},"url":"/socket.io/1/?t=1348305081311","xdomain":false,"secret":"your secret sauce2","cookies":{},"signedCookies":{"connect.sid":"o0wxRV+ykXOIxT3FNwsIG9OX"}} The connect.sid session is in redis but "counter" is in memorystore I think
|
hey glad you got it. thanks for your feedback, I published 0.1.1 on npm ensuring you will get either an error or the session; it will generate a lookup err if your key is wrong, but that's not your problem per your output. now you should get a better help on redis store repo, so closing this. |
Hi,
thanks for this package, I'm a bit confused how should I set the value (es. a reconnection counter) in the session? Should I use the "sessionStore" or the "session" from "connection", (err, socket, session) -> (this seems to be undefined inside the function)
console.log JSON.stringify sessionStore
{"sessions":{"gfFR572JqrZmCAWGwupdmFkD":"{"cookie": {"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"}}"}}
The text was updated successfully, but these errors were encountered: