will redis delete my old express.js sessions? will redis delete my old express.js sessions? express express

will redis delete my old express.js sessions?


Yes, connect-redis will make Redis clean out your sessions when they expire.

If I remember correctly, the default session timeout is 24 hours which to me is quite a long time to keep something idle in memory, but you can give it a ttl parameter to configure (in seconds) how long you want the sessions kept before Redis expires them.

If you want to make sure for yourself that Redis cleans things up for you, just set the timeout to 30 seconds and have a look in Redis for yourself after the timeout has expired;

app.use(express.session({  store: new RedisStore({    host: cfg.redis.host,    db: cfg.redis.db,    ttl: 30  }),   secret: 'foobar'}));

The ttl options is mentioned here and there is some minor extra detail on how it interacts with other options here.


It's working as expected. If I do a browser-only session (expires cookie when user-agent closes) then it lives in redis for 24 hours (I did not set a ttl option in connect-redis).

If I set a cookie to expire in 2 weeks, it lives in redis for 14 days.

You can check with these commands:

start redis-cli> keys *> ttl <key>