用RedisStore解决session的问题

用RedisStore解决session的问题

http://stackoverflow.com/questions/23249504/cant-use-connect-redis-in-express-js


//create express app
var http = require('http');
var express = require('express');
var app = express();

//add express-session
var session = require('express-session');
var RedisStore = require('connect-redis')(express);
app.use(session({
   store: new RedisStore({
      host: "redis://redistogo:e34d3***********************[email protected]:10072/"
   })
}));

//routing
var router1 = require('./router/router1')(app);
var router2 = require('./router/router2')(app);

//Deploying server
http.createServer(app).listen(3000, function () {
   console.log('Deployed!!');
});

报出了这样的错误

/home/luis/www/express2/node_modules/connect-redis/lib/connect-redis.js:96
  RedisStore.prototype.__proto__ = Store.prototype;
                                    ^
TypeError: Cannot read property 'prototype' of undefined
    at module.exports (/home/luis/www/express2/node_modules/connect-redis/lib/connect-redis.js:96:41)
    at Object.<anonymous> (/home/luis/www/express2/app.js:18:42)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

网络上大神的解答:


This:

var RedisStore = require('connect-redis')(express);

should be:

var RedisStore = require('connect-redis')(session);


Also remember to install express-session:

npm install express-session --save

If you plan to use Express 3.x, pick compatible version 1.4.7 of connect-redis to avoid the error.

 npm install [email protected] --save


你可能感兴趣的:(JavaScript,node)