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

I have an easy question for someone who use connect-redis.I want to use it with socket.io with the func

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'

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'

Share Improve this question asked Jun 19, 2013 at 8:44 JakubJakub 1,0479 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

connect-redis is a Redis-backed session store for Connect/Express, but it's inpatible 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)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745325424a4622634.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信