redis会话不能在服务器上工作

我在我的node.js express应用程序中使用redis进行会话。 它在我的开发框上正常工作,但在生产上,似乎redis会话没有被保存。

我没有看到任何types的错误,除了我无法login。

Redis运行w /相同的configuration。 但是当我运行redis-cli并键入' select 1 '(db)和KEYS '*'我什么也得不到。

  var RedisStore = require('connect-redis')(express); app.use(express.session({ store: new RedisStore({ host: cfg.redis.host, db: cfg.redis.db }), secret: 'sauce' })); 

cfg.redis.host是localhost,cfg.redis.db是1

这是我运行redis-cli monitor时得到的错误

 Error: Protocol error, got "s" as reply type byte 

几点build议。 你确定Redis在生产中使用相同的端口和密码吗? 如果您使用的是像Heroku这样的服务的SSL,则需要设置proxy:true以使Express在早期SSL终止之后处理到达的cookie。

  .use(express.session({ store: new RedisStore({ port: config.redisPort, host: config.redisHost, db: config.redisDatabase, pass: config.redisPassword}), secret: 'sauce', proxy: true, cookie: { secure: true } })) 

我需要以下config.js文件在Redisconfiguration值上传递:

 var url = require('url') var config = {}; var redisUrl; if (typeof(process.env.REDISTOGO_URL) != 'undefined') { redisUrl = url.parse(process.env.REDISTOGO_URL); } else redisUrl = url.parse('redis://:@127.0.0.1:6379/0'); config.redisProtocol = redisUrl.protocol.substr(0, redisUrl.protocol.length - 1); // Remove trailing ':' config.redisUsername = redisUrl.auth.split(':')[0]; config.redisPassword = redisUrl.auth.split(':')[1]; config.redisHost = redisUrl.hostname; config.redisPort = redisUrl.port; config.redisDatabase = redisUrl.path.substring(1); console.log('Using Redis store ' + config.redisDatabase) module.exports = config;