Search code examples
pythonsessionredisaiohttp

How to implement redis sessions expire in aiohttp


I can't find redis session expiration implementation in aiohttp redis session. Session saved in redis but then i check ttl AIOHTTP_SESSION_c8a63762a87d4c01a64991e268c35f54 there is no ttl for session key.

How to implement expiration to avoid old sessions grow? i am think about set

expire 'AIOHTTP_SESSION_'+session.identity 300

On every request in session middleware, is it convinient way or I am missing something?


Solution

  • You can see in the aiohttp-session documentation that RedisStorage take a max_age parameter. This is used to set the expiration time of the associated redis key in redis_storage.py