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?
BeginnerAnswer
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 requestReal-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.