feat: add ssl mode with non url connection + add redis cluster support

This commit is contained in:
vrenaville
2025-05-09 15:03:52 +02:00
parent 416a4660ae
commit 73845458ec
2 changed files with 23 additions and 3 deletions
+8
View File
@@ -13,6 +13,14 @@ The storage of sessions in Redis is activated using environment variables.
* ``ODOO_SESSION_REDIS_PORT`` is the redis port (default is ``6379``)
* ``ODOO_SESSION_REDIS_PASSWORD`` is the password for the AUTH command
(optional)
* ``ODOO_SESSION_REDIS_SSL`` is the SSL connection (default is ``true``)
(optional)
* ``ODOO_SESSION_REDIS_SSL_CERT_REQS`` is the SSL certificate requirements (default is
``required``), needed to be disabled when using self-signed certificates
(optional)
* ``ODOO_SESSION_REDIS_CLUSTER`` the redis in cluster mode (default is ``false``)
(optional)
* ``ODOO_SESSION_REDIS_URL`` is an alternative way to define the Redis server
address. It's the preferred way when you're using the ``rediss://`` protocol.
* ``ODOO_SESSION_REDIS_PREFIX`` is the prefix for the session keys (optional)
+15 -3
View File
@@ -40,8 +40,10 @@ url = os.getenv("ODOO_SESSION_REDIS_URL")
password = os.getenv("ODOO_SESSION_REDIS_PASSWORD")
expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION")
anon_expiration = os.getenv("ODOO_SESSION_REDIS_EXPIRATION_ANONYMOUS")
# For non url connections
ssl = os.getenv("ODOO_SESSION_REDIS_SSL", "1")
ssl_cert_reqs = os.getenv("ODOO_SESSION_REDIS_SSL_CERT_REQS", "1")
redis_cluster = os.getenv("ODOO_SESSION_REDIS_CLUSTER", "0")
@lazy_property
def session_store(self):
if sentinel_host:
@@ -49,8 +51,18 @@ def session_store(self):
redis_client = sentinel.master_for(sentinel_master_name)
elif url:
redis_client = redis.from_url(url)
elif is_true(redis_cluster):
redis_client = redis.RedisCluster(
host=host,
port=port,
password=password,
ssl=is_true(ssl),
ssl_cert_reqs=is_true(ssl_cert_reqs))
else:
redis_client = redis.Redis(host=host, port=port, password=password)
redis_client = redis.Redis(
host=host, port=port, password=password,
ssl=is_true(ssl),
ssl_cert_reqs=is_true(ssl_cert_reqs))
return RedisSessionStore(
redis=redis_client,
prefix=prefix,