用RedisStore解决session的问题
//create express appvar http = require('http');var express = require('express');var app = express();//add express-sessionvar session = require('express-session');var RedisStore = require('connect-redis')(express);app.use(session({ store: new RedisStore({ host: "redis://redistogo:e34d3***********************f4bb@albacore.redistogo.com:10072/" })}));//routingvar router1 = require('./router/router1')(app);var router2 = require('./router/router2')(app);//Deploying serverhttp.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.(/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 connect-redis@1.4.7 --save