martinrusev / django-redis-sessions

Session backend for Django that stores sessions in a Redis database
BSD 3-Clause "New" or "Revised" License
494 stars 106 forks source link

Extend session TTL on load() #45

Closed nuarhu closed 7 years ago

nuarhu commented 7 years ago

It seems to me (after looking into the TTL value of the session in Redis while browsing the Django webapp) that the session expiry is never extended on access. This means that the user is logged out from their session after the value specified in the settings (settings.SESSION_COOKIE_AGE) regardless of how active they have been during that time. They will loose any changes on the page, e.g. in a form, if they have been working on something when that TTL ends.

This pull requests simply extends the TTL on each call of redis_sessions.SessionStore.load() if the _session_key is not None (the session exists already).

Maybe there is a better way to achieve this?

There is an older issue #40 about this but with no solution.

nuarhu commented 7 years ago

Adding the setting SESSION_SAVE_EVERY_REQUEST = True will solve this problem better than the pull request.