Redis Store没有get方法?
http://senchalabs.github.com/connect/middleware-session.html提到.... “每个会话存储都必须实现以下方法:”
- .get(sid,callback)
- .set(sid, session,callback)
- .destroy(sid,callback)
我正在使用以下代码来尝试获取 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
//Redis store for storage
var sessionStore = require('connect-redis')(express);
...
...
app.use(express.session({secret: "keyboard cat",store: new sessionStore}));
http://senchalabs.github.com/connect/middleware-session.html mentions....
"Every session store must implement the following methods: "
- .get(sid,callback)
- .set(sid, session, callback)
- .destroy(sid, callback)
I'm using the following code to attempt to get the SID:
Node JavaScript, using Socket.io connection
io.sockets.on('connection', function(socket) {
var sid = socket.id;
if (sid) {
sessionStore.get(sid, function (error, session) {
console.log("Connect Sid: " + sid);
});
}
});
And i'm getting the following error:
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'
Inclusion of redis
//Redis store for storage
var sessionStore = require('connect-redis')(express);
...
...
app.use(express.session({secret: "keyboard cat",store: new sessionStore}));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看来您在实例化商店时忘记输入
new
了?Looks like you forgot to type
new
when you instantiated the store perhaps?取自: https://github.com/visionmedia/connect-redis
这似乎有效:
Taken from: https://github.com/visionmedia/connect-redis
This seems to work:
我是这样做的:
这样,如果需要,您可以稍后使用 socket.io 代码中的 sessionStore 对象引用会话数据。
I do it like this:
This way you can reference session data using the sessionStore object from socket.io code later if needed.