Skip to content
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

RedisStore session and Socket.IO #62

Closed
grigio opened this issue Sep 23, 2012 · 1 comment
Closed

RedisStore session and Socket.IO #62

grigio opened this issue Sep 23, 2012 · 1 comment

Comments

@grigio
Copy link

grigio commented Sep 23, 2012

Hi, I'd like to use redis as persistent sessionStore inside Socket.IO, probably I'm missing something because if I write the sessionStore from inside socket.io it is written in the memory store and not in redis.

some code parts:

express    = require 'express'
http       = require 'http'
redis      = require 'redis'
connect    = require('connect')
RedisStore = require('connect-redis')(express)

SessionSockets = require('session.socket.io')

app = module.exports = express()
app.set('port', 3000)
server = app.listen app.get('port')
io = require('socket.io').listen server

cookieParser = express.cookieParser('your secret sauce2')

# Redis as sessioStore
sessionStore = new RedisStore


sessionSockets = new SessionSockets(io, sessionStore, cookieParser)

sessionSockets.on "connection", (err, socket, session) ->

# ..
  socket.on "ping", (data) ->

    # Doesn't work, counter IS NOT saved in redis
    if session.counter
      ++session.counter
    else
      session.counter=1

    console.log '@sess2: '+JSON.stringify session


app.get "/test", (req, res) ->
  body = ""
   # Works, view IS saved in redis
  if req.session.views
    ++req.session.views
  else
    req.session.views = 1
    body += "<p>First time visiting? view this page in several browsers :)</p>"
  res.send body + "<p>viewed <strong>" + req.session.views + "</strong> times.</p>"

The connect.sid session is in redis but "counter" is in memorystore I think

redis 127.0.0.1:6379> get sess:o0wxRV+ykXOIxT3FNwsIG9OX
"{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"}}"

see also:
wcamarao/session.socket.io#2 (comment)

@tj
Copy link
Owner

tj commented Sep 26, 2012

dont post coffeescript plzzZz

@tj tj closed this as completed Sep 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants