简体   繁体   English

Connect-redis存储不适用于socket.io

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

I have an easy question for someone who use connect-redis. 对于使用connect-redis的人,我有一个简单的问题。

I want to use it with socket.io with the function io.set('store', something) . 我想在socket.io中使用它与函数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' 它说Object #<RedisStore> has no method 'subscribe'

connect-redis is a Redis-backed session store for Connect/Express, but it's incompatible with the 'store protocol' that socket.io uses. connect-redis是Redis支持的Connect / Express会话存储,但它与socket.io使用的“存储协议”不兼容。

Instead, you need to use the Redis store implementation shipped with socket.io : 相反,您需要使用socket.io附带的Redis存储实现:

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 ) docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM