如何解决connection.session问题

Gan*_*mar 16 node.js

我在使用时会收到轰鸣声警告NODE_ENV=production.有什么办法解决这个问题?

警告:connection.session()MemoryStore不是
为生产环境设计的,因为它会泄漏
内存,显然只能在单个进程中工作.

Bij*_*lle 8

将Redis用作会话管理器可能是个好主意.看起来好像你正在使用Express或Connect框架,对于它们中的任何一个,你可以使用npm包connect-redis(已经安装了Redis).安装完成后,快速代码将如下所示:

var express = require ( 'express' )
   , RedisStore = require ( 'connect-redis' ) ( express )
   , sessionStore = new RedisStore ()
   , app = express.createServer ()
   ;

app.configure ( function () {

   app.use ( express.cookieParser () );
   app.use ( express.session ( {
    secret: "keyboard cat", store: sessionStore, key: 'hello.sid'
   } ) );
...
Run Code Online (Sandbox Code Playgroud)

  • @GaneshKumar这个[问题](http://stackoverflow.com/questions/8749907/what-is-a-good-session-store-for-a-single-host-node-js-production-app)处理特别是你的问题.您可能希望探索链接问题中描述的安全cookie路由,而不是数据库. (2认同)