我的快递应用程序使用PassportJS存储auth会话,但它在redis存储中创建了一个荒谬的键数,所有键看起来都一样:
"{\"cookie\":{\"originalMaxAge\":null,\"expires\":null,\"httpOnly\":true,\"path\":\"/\"},\"passport\":{}}"
他们确实有一个TTL,但商店的规模正在增长,没有充分的理由。知道为什么要创建它们吗?我的钥匙看起来像:
"sess:8R3A-k6dARJvxXFdAXr5nTG7MeC7JTxb"
"sess:s4VYC-k-nmfSf7n-qGQJimFmt30EYNDp"
"sess:BS7WO92Nyl5R0wAbJ-Vo9o8w1apu0kp7"
"sess:0B1AKS6-MCclPvOXV0nlvNio8U8fxyQO"
"sess:v0UWf60LMwKmMVZgo4RWumX313yPsiD0"
如果我只是眼球,每隔一两个钟就会创建大约10个键。
这是我的会话代码的外观:
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函数返回redis客户端的实例:
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;
};