在生产中使用MemoryStore [英] Using MemoryStore in production

查看:152
本文介绍了在生产中使用MemoryStore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我第一次在生产"模式下运行Node.js应用程序,并收到以下警告:

Today I ran my Node.js application in "production" mode for the first time and got this warning:

Warning: connection.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and obviously only work within a single process.

我只需要运行一个进程,但是我应该使用什么呢?我希望我的会话驻留在RAM中以便快速访问.我还希望能够通过仅关闭Node应用程序来丢弃所有会话.

I only need to run a single process, but what should I use instead? I want my sessions to reside in RAM for fast access. I also want to be able to discard all the sessions by simply shutting down the Node app.

仅仅为完成此简单任务而安装Redis,MongoDB或其他数据库似乎是过大的选择.我也不明白为什么不应该真正使用Node中包含MemoryStore?

It seems an overkill to install Redis, MongoDB or another database just for this simple task. I also don't understand why is MemoryStore included in Node when it should not really be used?

推荐答案

MemoryStore仅用于(快速)开发模式,因为如果您的应用重新启动(进程终止),您将丢失所有会话数据(驻留在内存中).该过程).

MemoryStore is just for (rapid) development mode, because if your app restarts (process dies) you will lose all the session data (that resided in the memory of that process).

如果您不想使用数据库,请改用加密的cookie存储.

If you don't want to use a database, use encrypted cookie storage instead.

http://www.senchalabs.org/connect/cookieSession.html

这篇关于在生产中使用MemoryStore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆