2012-03-24 234 views
16

使用NODE_ENV=production时,我收到警告。这有什么解决办法?如何解决connection.session问题

警告:connection.session()MemoryStore的不是
设计用于生产环境,因为它会泄漏
内存,显然只有一个进程中运行。

+0

你的代码是什么? – Mustafa 2012-03-24 07:24:57

+2

看看这个答案: [http://stackoverflow.com/questions/10760620/using-memorystore-in-production#10761522][1] [1]:HTTP: //stackoverflow.com/questions/10760620/using-memorystore-in-production#10761522 – 2012-05-25 21:26:08

回答

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' 
    })); 
... 
+0

我使用Redis进行会话存储。但在这里我只需要进行管理员身份验证。这就是为什么我正在寻找简单的解决方案 – 2012-03-24 21:18:59

+2

@GaneshKumar this [so question](http://stackoverflow.com/questions/8749907/what-is-a-good-session-store-for-a-single-host- node-js-production-app)专门处理您的问题。也许不是数据库,你可能希望探索链接问题中描述的安全cookie路由。 – 2012-03-25 10:11:41

+0

谢谢audio.zoom – 2012-03-25 15:28:43