How to clear all sessions in Nodejs (heroku + redis)?

I am using nodejs (expressjs) hosted on heroku .

Sessions are stored in redis ( Redistogo plugin for heroku):

RedisStore = require('connect-redis')(express)
app.use express.session
      secret: process.env.CLIENT_SECRET
      cookie: { maxAge: 604800000 }
      store: new RedisStore {client: redis}

After the user logs in, I store his information in req.session

after_user_logged_id = (req, user)->    
  req.session.current_user =
    id: user._id
    name: user.name

I need to restart the server and clear all sessions: log out all users to force them to log in again. How should I do it? Restarting the redis plugin does not help.

+5
source share
2 answers

redis.flushdb() , - redis. "sess: *". , del *, - :

redis.keys("sess:*", function(err, key) {
  redis.del(key, function(err) {
  });
});
+6

redis:

RedisStore = require('connect-redis')(express)
rtg   = require('url').parse process.env.REDISTOGO_URL
redis = require('redis').createClient rtg.port, rtg.hostname  
redis.auth rtg.auth.split(':')[1] # auth 1st part is username and 2nd is password separated by ":"
  try
    console.log "clean sessions"
    redis.flushdb()
  catch err
    console.log "error:", err
0

All Articles