nodejs express session用法(含保存到redis)
2021-07-08 12:04
标签:var code class initial host use nec ejs bsp 普通用法: session保存到redis: nodejs express session用法(含保存到redis) 标签:var code class initial host use nec ejs bsp 原文地址:http://www.cnblogs.com/gouge/p/7097764.html 1 var express = require(‘express‘);
2 var session = require(‘express-session‘);
3
4 var app = express();
5
6 app.use(session({
7 name: ‘test1‘, // 非常重要,用于区分两个系统的session
8 secret: ‘test1 cat‘,
9 cookie: { maxAge: 5 * 60 * 60 * 1000 },
10 resave: true,
11 saveUninitialized: true
12 }));
1 var express = require(‘express‘);
2 var session = require(‘express-session‘);
3 var redisStore = require(‘connect-redis‘)(session);
4
5 var app = express();
6
7
8 var redisCfg = {
9 host:"127.0.0.1",
10 port:"6379",
11 auth_pass:"",
12 db:0
13 };
14
15 app.use(session({
16 store: new redisStore(redisCfg),
17 secret: ‘test‘, // 可修改成自己的
18 cookie: { maxAge: 10 * 60 * 1000 },
19 resave: true,
20 saveUninitialized: false
21 }));
下一篇:Webpack
文章标题:nodejs express session用法(含保存到redis)
文章链接:http://soscw.com/essay/102361.html