Redis Storage Session Preparation method

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.