http://senchalabs.github.com/connect/middleware-session.html提及...... “每个会话存储必须实现以下方法:”
我正在使用以下代码尝试获取SID:
节点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}));
答案 0 :(得分:1)
您可能忘记在实例化商店时忘记输入new
吗?
答案 1 :(得分:0)
取自: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); });
答案 2 :(得分:0)
我这样做:
var RedisStore = require('connect-redis')(express);
var sessionStore = new RedisStore;
...
app.use(express.session({secret: "keyboard cat",store: sessionStore}));
这样,如果需要,您可以稍后使用socket.io代码中的sessionStore对象引用会话数据。