[MIG] session_redis: Migration to 16.0 (#392)

Co-authored-by: Hugo Santos <hugo.santos@factorlibre.com>
This commit is contained in:
Vincent Renaville
2022-11-09 13:39:53 +01:00
committed by GitHub
co-authored by GitHub Hugo Santos
parent dddd130e79
commit 988d4906bf
2 changed files with 25 additions and 27 deletions
+9 -27
View File
@@ -6,8 +6,8 @@ import os
from .strtobool import strtobool
import odoo
from odoo import http
from odoo.tools import config
from odoo.tools.func import lazy_property
from .session import RedisSessionStore
@@ -52,22 +52,10 @@ def session_store(self):
redis_client = redis.from_url(url)
else:
redis_client = redis.Redis(host=host, port=port, password=password)
return RedisSessionStore(
redis=redis_client,
prefix=prefix,
expiration=expiration,
anon_expiration=anon_expiration,
session_class=http.OpenERPSession,
)
def session_gc(session_store):
"""Do not garbage collect the sessions
Redis keys are automatically cleaned at the end of their
expiration.
"""
return
return RedisSessionStore(redis=redis_client, prefix=prefix,
expiration=expiration,
anon_expiration=anon_expiration,
session_class=http.Session)
def purge_fs_sessions(path):
@@ -89,14 +77,8 @@ if is_true(os.environ.get("ODOO_SESSION_REDIS")):
sentinel_port,
)
else:
_logger.debug(
"HTTP sessions stored in Redis with prefix '%s' on " "%s:%s",
prefix or "",
host,
port,
)
http.Root.session_store = session_store
http.session_gc = session_gc
_logger.debug("HTTP sessions stored in Redis with prefix '%s' on "
"%s:%s", prefix or '', host, port)
http.Application.session_store = session_store
# clean the existing sessions on the file system
purge_fs_sessions(odoo.tools.config.session_dir)
purge_fs_sessions(config.session_dir)
+16
View File
@@ -4,6 +4,7 @@
import json
import logging
from odoo.service import security
from odoo.tools._vendor.sessions import SessionStore
from . import json_encoding
@@ -96,3 +97,18 @@ class RedisSessionStore(SessionStore):
keys = self.redis.keys('%s*' % self.prefix)
_logger.debug("a listing redis keys has been called")
return [key[len(self.prefix):] for key in keys]
def rotate(self, session, env):
self.delete(session)
session.sid = self.generate_key()
if session.uid and env:
session.session_token = security.compute_session_token(session, env)
self.save(session)
def vacuum(self):
""" Do not garbage collect the sessions
Redis keys are automatically cleaned at the end of their
expiration.
"""
return None