Redis Storage Session Preparation method requires three modules;
1. Redis
2, Express-session
3, Connect-redis
The configuration method code snippet in the project is as follows;
First connect Redis, connect to Redis database;
1 var redis = require (' Redis '); 2 var redis_client = redis.createclient (' 6379 ', redis_host); 3 function (Err) {console.error (err);}); 4 function () {});
Configuring Express-session and Connect-redis modules;
1 varSession = require (' express-session ');2 varRedisstore = require (' Connect-redis ')) (session);3 varSession_options = {4 Secret:system_secret_key,5Saveuninitialized:true,6Resave:false,7Proxyfalse,8Rolling:true,9Cookie: {MAXAGE:30 * * * * *, HttpOnly:true, domain:is_development? ":", Secure:false}Ten }; One //configuration middleware; AApp.use (Session (_.extend ({store:NewRedisstore ({ - Client:redis_client, -TTL:30 * 24 * 60 * 60 the}), session_options));
Do not understand the points,
1, session_options Why do not fill in the new Redisstore ({}) inside, but alone on the outside;
2, Session_options set the cookie parameter inside the time and new Redisstore ({}) inside the TTL time is different;
3, about _extend, this method is Lodash in the method, but did not find the usage instructions, do not know what is doing;
Redis Storage Session Preparation method