Back to results for “Commands”
Redis › Session Management with Redis

How do you extend a user's session expiration time each time they make a new request, keeping active users logged in?

Beginner

Answer

You call the EXPIRE command with a fresh expiration duration each time a user makes a request, effectively resetting their session's countdown timer, ensuring an actively browsing user's session stays alive, while a genuinely inactive user's session will still naturally expire after the configured period of inactivity.
GET session:abc123
EXPIRE session:abc123 1800 -- reset the timer on each request
Real-world example A shopping website extends a customer's session expiration every time they view a new page, ensuring an actively shopping customer is never unexpectedly logged out mid checkout, while inactive sessions still clean up automatically.

Common follow-ups: Should the session expiration be extended on every single request or only certain ones?;What is a reasonable session timeout duration for a typical web application?