Sails.js MemoryStore在SailsJs应用程序中泄漏内存

Sails.js MemoryStore在SailsJs应用程序中泄漏内存,sails.js,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. 我知道有人问过类似的问题,答案似乎是定期用类似的代码清理sessionStore function sessionClea

几天前,我在生产中第一次运行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.
我知道有人问过类似的问题,答案似乎是定期用类似的代码清理sessionStore

function sessionCleanup() {
   sessionStore.all(function(err, sessions) {
      for (var i = 0; i < sessions.length; i++) {
         sessionStore.get(sessions[i], function() {} );
      }
   });
}
函数sessionCleanup(){
sessionStore.all(函数(错误,会话){
对于(var i=0;i

如何获取对sails.js中sessionStore的引用?

您所需要做的只是将
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:'
};
module.exports.session={
秘密:'',
适配器:“redis”,
主机:“localhost”,
港口:6379,
ttl:,
通过:
前缀:“sess:”
};

您最好不要使用MemoryStore。如果您将以生产模式在内存中存储数据,那么您将面临许多扩展问题。我如何禁用它?只需在设置会话配置的位置更新您的Sails配置。我的会话配置(config/session.js)只有一个secret属性。没有别的了。在阅读了Sails文档和里面的注释之后,我仍然找不到禁用sessionStore的方法。您还必须为会话存储提供另一个适配器。看一看完整的示例-