最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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)

发布评论

评论列表(0)

  1. 暂无评论