Redis › Session Management with Redis

How would you design a session management system that supports both a sliding expiration for active users and an absolute maximum session lifetime regardless of activity?

Advanced

Answer

You would maintain two separate expiration mechanisms, extending a sliding expiration key on every user request to keep active sessions alive, while also checking a separate absolute expiration timestamp stored within the session data itself, forcibly ending the session once that absolute maximum lifetime is reached even if the user has remained continuously active the entire time.
HSET session:abc123 absoluteExpiry '2026-09-08T10:00:00'
EXPIRE session:abc123 1800 -- sliding expiration reset each request
-- Application checks absoluteExpiry before honoring the session
Real-world example A banking application allows a customer's session to stay alive through continuous activity using a sliding expiration, but forces a complete re-login after twelve hours regardless of activity, using a separate absolute expiration check for enhanced security.

Common follow-ups: Why would an application want both a sliding and an absolute session expiration together?;How do you handle a user who is actively working when their absolute session expiration is reached?