Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect-redis store don't work with socket.io

I have an easy question for someone who use connect-redis.

I want to use it with socket.io with the function io.set('store', something). I don't know why, when I do

var RedisSessionStore = require('connect-redis')(express);
var sessionStore = new RedisSessionStore();

app.use(express.session({
  secret: 'some totally secret key',
  cookie: {
    maxAge: 1000 * 60 * 60
  },
  store: sessionStore
}));

//and then I wan't to use the session store for socket.io
io.set('store', sessionStore);

It says Object #<RedisStore> has no method 'subscribe'

like image 642
Jakub Avatar asked Jun 19 '13 08:06

Jakub


1 Answers

connect-redis is a Redis-backed session store for Connect/Express, but it's incompatible with the 'store protocol' that socket.io uses.

Instead, you need to use the Redis store implementation shipped with socket.io:

var SocketIoRedisStore = require('socket.io/lib/stores/redis'),
    redis              = require('socket.io/node_modules/redis');
...
io.set('store', new SocketIoRedisStore({
  redisPub    : redis.createClient(),
  redisSub    : redis.createClient(),
  redisClient : redis.createClient()
}));

(docs)

like image 101
robertklep Avatar answered Nov 06 '22 15:11

robertklep