martinrusev / django-redis-sessions

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

Update sessionid expires value #40

Closed sodrian closed 8 years ago

sodrian commented 8 years ago

Hey!

I use django-redis-sessions for session backend, here is my configuration:

SESSION_CACHE_ALIAS = 'redis'
SESSION_COOKIE_AGE = 3600 * 24 * 7
SESSION_ENGINE = 'django.contrib.sessions.backends.cache'

CACHES = {
    'redis': {
        'BACKEND': 'redis_cache.RedisCache',
        'LOCATION': '{0}:{1}'.format(REDIS_HOST, REDIS_PORT),
    }
}

The problem here is that sessionid key in cookies does not update and lives precisely for 1 week and users have to relogin every week.

Is there a way for sessionid to autoupdate on every request from user?

nuarhu commented 7 years ago

Why did you close this? Is this solved for you? We do have the same problem. Could you share your solution?

martinrusev commented 7 years ago

@nuarhu How about this one: https://stackoverflow.com/questions/3044799/in-django-how-to-renew-expiry-date-for-current-session

If you set SESSION_SAVE_EVERY_REQUEST = True, Django will automatically update the cookie expiry date

https://github.com/django/django/blob/1ce04bcce0076360623ae164afd3541a5c031af2/django/contrib/sessions/middleware.py#L46

nuarhu commented 7 years ago

I've added this setting: SESSION_SAVE_EVERY_REQUEST = True and that did the trick. Thanks for the quick answer and the link, it had the solution!