I am using ioRedis coupled with express-session in my NodeJS app and I'd like to fire an event when a session expires. I wrote this:
let Redis = require('ioredis');
let clientRedis = new Redis();
let RedisStore = require('connect-redis')(session);
const sessionMiddleware = session({
store: new RedisStore({
client: clientRedis,
}),
secret: SESSIONSECRET,
resave: true,
saveUninitialized: true,
cookie: {
maxAge: 5000,
secure: false,
httpOnly: true,
domain: config.get('app.domainecookie')
}
});
app.use(sessionMiddleware);
I read the doc and I have no clue on how capture the "expire" event... There must be a ioredis function, but I don't see which one. I read a lot of questions talking about key expiration but this is not a particular key I want to get the notifications of, I want the session of the user to get a notification (I'm handling the messages with a socket which works like a charm, I just don't know how to capture the event).
For the moment I created an express middleware firing timed out functions in a custom "activeSessions" object, but this is using memory of my NodeJS.app, there must be a better way to do this.
Thanks in advance :)