Redis商店没有get方法?

http://senchalabs.github.com/connect/middleware-session.html提及….“每个会话商店必须实施以下方法:”

  1. 获得(SID,callback)
  2. .set(sid,session,callback)
  3. .destroy(sid,callback)

我正在使用下面的代码来尝试获取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

 //Redis store for storage var sessionStore = require('connect-redis')(express); ... ... app.use(express.session({secret: "keyboard cat",store: new sessionStore})); 

看起来你忘了在实例化商店时inputnew的名字?

取自: 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); }); 

我这样做:

 var RedisStore = require('connect-redis')(express); var sessionStore = new RedisStore; ... app.use(express.session({secret: "keyboard cat",store: sessionStore})); 

这样,如果需要,可以使用来自socket.io代码的sessionStore对象来引用会话数据。