Node.JS - express - connect-redis how to delete a record

I have an example directly derived from an express document.

app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat" }));
var RedisStore = require('connect-redis');
app.use(express.cookieParser());
app.use(express.session({ secret: "keyboard cat", store: new RedisStore }));

I know that this code will create a session id and automatically save the session id in redis databse. Correctly?

Now let's say the generated session_id was 555444, how can I delete a record when it is no longer needed?

+3
source share
5 answers

Are any of these actions being performed?

store.destroy('555444', function(err) { ... })

or

app.get('/', function(req, res) {
    if (req.session.sid == '555444') {
        req.session.destroy(function(err) { ... });
    }
})
+2
source

I faced a similar situation where I wanted to destroy an existing session and clear the cookie during the logout. This seems to work just fine for me (the store is an instance of RedisStore).

app.get('/logout', function (req, res) {
  res.contentType('json');
  store.destroy(req.sessionID, function () {
    req.session.destroy(function () {
      res.clearCookie(sessionOpts.key, { path: '/' });
      res.send({ success: true });
    });
  });
});
+1
source

, redis, ( maxAge). -

0

Github, backbone.js, , , , if you want to check it out. I have contributed to the reconfiguration of the backbone platforms.

Scroll it here on github

  • socket.io for real-time multi-user editing
  • mongodb data storage
  • redis for session management
  • redis pub / sub for record locks, so two users do not try to edit the same Todo
0
source

You just need to provide the sessionID to the destroy method, this will clear this session key from the Redis database. Here is the code that worked for me:

req.session.destroy(req.sessionID, function () {
    // Passport logout
    req.logout();
});
0
source

All Articles