I have written a simple node/express/redis app, that stores a custom session id in redis. It works. But being new to redis, I'm only able to locate the sessionID, but not jsessionid in redis.
var sessionStore = new RedisStore({
host: redisHost,
port: redisPort,
db: redisDB
});
app.use(session({
name: 'jsessionid', // access using req.cookies['jsessionid']
secret: 'keyboard cat',
store: sessionStore
}));
app.get('/awesome', function(req, res) {
if(req.session.lastPage) {
res.write('Last page was: ' + req.session.lastPage + '. And session id was: ' + req.sessionID + '. And jsessionid is ' + req.cookies['jsessionid'] + '. ');
}
req.session.lastPage = '/awesome';
res.end('Your Awesome.');
});
So, when I do http://localhost:3000/awesome and reload it, then it prints out the following as expected:
"Last page was: /awesome. And session id was: kOnhpfyFQlil76eVXIbIBJTUNU7GzhDG. And jsessionid is s:kOnhpfyFQlil76eVXIbIBJTUNU7GzhDG.KF3B6TLxMl084VI2rvYw+hz4u/wQr5IL7n+//gnH9mQ. Your Awesome."
And I can find the sessionID in redis-cli by doing:
127.0.0.1:6379> select 2
OK
127.0.0.1:6379[2]> keys *
1) "sess:kOnhpfyFQlil76eVXIbIBJTUNU7GzhDG"
But I"m unable to find the jsessionid in redis. I think it should exist somewhere. Please help.
The name option for the express-session middleware is only the name of the cookie. You can change the prefix though by setting the prefix option (defaults to 'sess:') in your RedisStore config. See here for more options you can set.