node.js - Express session stored in redis for anonymous -


i'm using express 4.0 module express-session, connect-redis , passport manage sessions. ok login , logout, can retrieve session etc.

but i've noticed weird: when i'm anonymous, if i'm going redis , type:

$ keys * 

redis return entry 1) "sess:vwdwtjpxkitmqq77xi8cotlltdrz7s8s" if nobody connected. when i'm connect, key replaced corresponding session. , when i'm logout, key changes again another. when anonymous user call url, req.sessionid set.

in site https://engineering.linkedin.com/nodejs/blazing-fast-nodejs-10-performance-tips-linkedin-mobile i've read create session anonymous (7. go session-free) , think it's related.

i add middlewhere in main app.js file like:

var   passport = require('passport'),   user = require('../models/user'),   localstrategy = require('passport-local').strategy,   session = require('express-session'),   redisstore = require('connect-redis')(session);  app.use(session({   store: new redisstore(app.locals.services.session.config),   secret: 'mysecretstring' }));  app.use(passport.initialize()); app.use(passport.session());  passport.use(user.createstrategy()); passport.serializeuser(user.serializeuser()); passport.deserializeuser(user.deserializeuser()); 

i have problem if start fresh server , if try homepage i'm doing nothing:

index: function (req, res) {   res.render('home/index'); } 

even in case, new key created in redis.

note: if remove both lines, no key created.

app.use(passport.initialize()); app.use(passport.session()); 

so, question is: how avoid key creation in redis anonymous users ? (and, idea not store session anonymous ?).

thanks !

if don't want new session created each request, set saveuninitialized false in express-session middleware:

app.use(session({   store             : new redisstore(app.locals.services.session.config),   secret            : 'mysecretstring',   saveuninitialized : false, })); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -