I have a big problem with sessions.
I drive to create an application around “Redis” nodejs with different libraries as express.
But suddenly the sessions no longer works. And I do not understand why.
So I reformatted my server and reinstall all properly.
(I am using Debian 6)
And the basic test is still not working: (.
Here’s the test:
var express = require('express');
var app = express.createServer();
var RedisStore = require('connect-redis')(express);
app.use(express.bodyParser());
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));
app.get('/', function(req, res){
var sess = req.session;
req.session.visitCount = req.session.visitCount ? req.session.visitCount + 1 : 1;
if (sess.views) {
res.setHeader('Content-Type', 'text/html');
res.write('<p>views: ' + sess.views + '</p>');
res.write('<p>expires in: ' + (sess.cookie.maxAge / 1000) + 's<p/>');
res.write('<p>You have visited this page ' + req.session.visitCount + ' times</p>');
res.end();
sess.views++;
} else {
sess.views = 1;
res.end('welcome to the session demo. refresh!');
}
});
app.listen(4000);
the program runs correctly (no error).
but when I use the “sess.views” is never valid
so I always see : welcome to the session demo. refresh!
I am a bit desperate.
Thank you in advance for your help
code
I believe
sess.views++needs to be called beforeres.end()just like TJ’s examplepackages installed
System information
Curl example
Works just fine!