cho*_*ovy 5 redis node.js express
我在我的node.js express app中使用redis进行会话.它在我的开发盒上工作正常,但在生产时,似乎redis会话没有被保存.
我没有看到任何类型的错误,除了我无法登录.
Redis正在运行w /相同的配置.但当我运行redis-cli并键入' select 1'(数据库)时,KEYS '*'我什么都没得到.
var RedisStore = require('connect-redis')(express);
app.use(express.session({
store: new RedisStore({
host: cfg.redis.host,
db: cfg.redis.db
}),
secret: 'sauce'
}));
Run Code Online (Sandbox Code Playgroud)
cfg.redis.host是localhost,cfg.redis.db是1
这是我跑步时遇到的错误 redis-cli monitor
Error: Protocol error, got "s" as reply type byte
Run Code Online (Sandbox Code Playgroud)
一些建议。您确定 Redis 在生产中使用相同的端口和密码吗?如果您将 SSL 与 Heroku 等服务一起使用,则需要设置 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 }
}))
Run Code Online (Sandbox Code Playgroud)
我需要以下 config.js 文件来传递 Redis 配置值:
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;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1211 次 |
| 最近记录: |