MemoryStore在SailsJs App中泄漏内存

win*_*ime 7 sails.js

几天前,我第一次在生产中运行SailsJs应用程序.这个警告出现了.

Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Run Code Online (Sandbox Code Playgroud)

我知道已经提出了类似的问题,答案似乎是定期用代码清理sessionStore.

function sessionCleanup() {
   sessionStore.all(function(err, sessions) {
      for (var i = 0; i < sessions.length; i++) {
         sessionStore.get(sessions[i], function() {} );
      }
   });
}
Run Code Online (Sandbox Code Playgroud)

如何在sails.js中引用sessionStore?

Eug*_*kov 5

所有你需要做的只是config/session.js用另一个适配器Redis 替换内存适配器.

module.exports.session = {
  secret: '<YOUR_SECRET>',
  adapter: 'redis',
  host: 'localhost',
  port: 6379,
  ttl: <REDIS_TTL_IN_SECONDS>,
  pass: <REDIS_PASSWORD>
  prefix: 'sess:'
};
Run Code Online (Sandbox Code Playgroud)