在Memcached上存储Express会话

时间:2018-03-11 13:09:17

标签: node.js express memcached connection-pooling express-session

我正在使用节点+表达式应用程序并使用connect-memcached来存储使用Memcached客户端与Memcached服务器通信的快速会话。我想通过连接池使用Memcached。到目前为止,我已经尝试过这个: -

var session = require('express-session');
var MemcachedStore = require('connect-memcached')(session);
var servers = [];
if (typeof cacheAddr === 'string') servers.push(cacheAddr + ':' + cachePort);
else {
  for(var i = 0; i < cacheAddr.length; i++)
    servers.push(cacheAddr[i] + ':' + cachePort);
  }
  var store = {
    secret  : secret,
    key     : 'its',
    proxy   : 'true',
    store   : new MemcachedStore({
      hosts: servers,
      prefix: 'sess:',
      poolSize: 200
    }),
    saveUninitialized: true,
    resave: true,
    unset: 'destroy'
  };
}
var sessionStore = session(store);
我的memcached服务器上的 netstat显示来自我的应用程序服务器的2个连接。 任何想法,如何去做?

1 个答案:

答案 0 :(得分:0)

It is correct. The load was not enough, so I was not seeing 200 active connections. On increasing the load, I got to see 200 active connections.