我应该怎么做才能将数据存储到使用connect-redis进行的会话中 [英] What should I do to store data to session with connect-redis
本文介绍了我应该怎么做才能将数据存储到使用connect-redis进行的会话中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要存储帐户的username
进行会话.我通过expressjs框架使用node.js,并且尝试使用connect-redis
来存储会话,例如 expressjs .
请教我如何存储和获取变量数据
I want to store username
of an account to session. I working with node.js by expressjs framework and I tried to use connect-redis
to store session like tutorial of expressjs.
Pls show me how to store and get data of variable
推荐答案
使用redis-connect配置expressSession后,立即添加以下功能:
Once you configure your expressSession with redis-connect, immediately add the following function:
expressApp.use(function(req, res, next) {
if(req.session.user){
console.log("Session variable already set: " + req.session.user);
}
else{
req.session.user = 'username';
console.log("Session variable not set");
console.log("Setting Session variable now: " + req.session.user);
}
})
现在,您可以在nodejs应用程序中的任何位置使用此会话变量.
Now you can use this session variable anywhere in your nodejs app.
这篇关于我应该怎么做才能将数据存储到使用connect-redis进行的会话中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文