My express app uses PassportJS for storing auth session but it creates a ridiculous number of keys in the redis store and all the keys look the same:
"{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}"
They do have a TTL but the store is growing in size for no good reason. Any idea why these are being created? My keys looks like:
"sess:8R3A-k6dARJvxXFdAXr5nTG7MeC7JTxb"
"sess:s4VYC-k-nmfSf7n-qGQJimFmt30EYNDp"
"sess:BS7WO92Nyl5R0wAbJ-Vo9o8w1apu0kp7"
"sess:0B1AKS6-MCclPvOXV0nlvNio8U8fxyQO"
"sess:v0UWf60LMwKmMVZgo4RWumX313yPsiD0"
If I just eyeball it, roughly around 10 keys are being created every second or two.
This is how my session code looks:
var express = require('express'),
....
session = require('express-session'),
redisStore = require('connect-redis')(session);
...
app.use(express.static(path.resolve('./public')));
//Redis
var redisClient = redisHelper.init();
app.use(session({
secret: '...',
store: new redisStore({
client: redisClient,
ttl: 86400
}),
resave: false,
saveUninitialized: false,
cookie:{maxAge:86400}
}));
//Passport
app.use(passport.initialize());
app.use(passport.session());
...
Redis init function returns an instance of a redis client:
exports.init = function () {
redisClient = redis.createClient(config.redis.port, config.redis.server, {});
redisClient.auth(config.redis.auth);
redisClient.on('error', function (error) {
//TODO: log the error
winston.error('Error while talking to Redis', {message: error});
});
return redisClient;
};