简体   繁体   中英

How to limit 10 concurrent sessions/connections in nodeJS Application

I am working on NodeJS (middleware used- Express-session, session-file-store) application where I have defined user permissions as- 'view', 'view-edit' and 'edit'. This application should have max total active session or active user count to be 10.

Should I use session count? I have to maxAge of session limiting to 5 min.

So problem is after a session is expired then session count should be updated. but once session is expired I can't traces it..

Finally I got a solution to get the session count if we are using file-session-store in node.js

//file store parameters
var sess_options = {
path: "/tmp/sessions/",
useAsync: true
};
// sess_count variable
var sess_count = 0;

var file_store = new FileStore(sess_options);
router.use(session({
  store : file_store,
  resave : false,
  saveUninitialized : true,
  secret : 'asts123',
 rolling : false,
cookie : {  httpOnly: false,
secure : true,
maxAge : 60000
}
}));

router.use(function(req, res, next) {
file_store.length(function session_count(a,len) {
  sess_count = len;
  console.log("Total active session count is " + sess_count);
  console.log("============");
});
 return next();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM