gpt4 book ai didi

node.js - Req.session undefined with express 4 and Redis store, express-session

转载 作者:可可西里 更新时间:2023-11-01 11:35:43 24 4
gpt4 key购买 nike

似乎无法弄清楚如何将 redis 存储用于 Express 4 的 session ,一些示例代码如下所示:

var express       = require('express');
var app = express();
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var RedisStore = require('connect-redis')(session);

app.use(cookieParser());
app.use(session({
store: new RedisStore({
host: 'localhost',
port: 6379,
}),
secret: 'secret',
resave: false,
saveUninitialized: true
}));
app.get('/', function (req, res) {
console.log(req.session); // undefined! :(
});
app.listen(3000);

如你所见,上面的 req.session 似乎总是未定义的,显然无法在其中存储任何变量......

最佳答案

当然,最令人沮丧的问题有最简单的答案……从未安装过 Redis 客户端。将来任何人的链接 - http://redis.io/topics/quickstart :脸掌:

关于node.js - Req.session undefined with express 4 and Redis store, express-session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34581834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com