http://senchalabs.github.com/connect/middleware-session.html提到..。“每个会话存储必须实现以下方法:”
我使用以下代码尝试获取SID:
Node JavaScript,使用Socket.io连接
io.sockets.on('connection', function(socket) {
var sid = socket.id;
if (sid) {
sessionStore.get(sid, function (error, session) {
console.log("Connect Sid: " + sid);
});
}
});我得到了以下错误:
TypeError: Object function RedisStore(options) {
options = options || {};
Store.call(this, options);
this.client = new redis.createClient(options.port || options.socket, options.host, options);
if (options.pass) {
this.client.auth(options.pass, function(err){
if (err) throw err;
});
}
if (options.db) {
var self = this;
self.client.select(options.db);
self.client.on("connect", function() {
self.client.send_anyways = true;
self.client.select(options.db);
self.client.send_anyways = false;
});
}
} has no method 'get'红系植物
//Redis store for storage
var sessionStore = require('connect-redis')(express);
...
...
app.use(express.session({secret: "keyboard cat",store: new sessionStore}));发布于 2011-09-14 14:25:52
摘自:https://github.com/visionmedia/connect-redis
This means express users may do the following, since express.session.Store points to the connect.session.Store function:这似乎是可行的:
express.session.Store(sid, function(){ console.log("Connect Sid: " + sid); });发布于 2011-09-14 14:00:33
看起来您可能在实例化商店时忘记输入new了吗?
发布于 2012-07-28 22:13:42
我这样做:
var RedisStore = require('connect-redis')(express);
var sessionStore = new RedisStore;
...
app.use(express.session({secret: "keyboard cat",store: sessionStore}));这样,以后如果需要,可以使用sessionStore对象从socket.io代码中引用会话数据。
https://stackoverflow.com/questions/7417500
复制相似问题