diff --git a/session_redis/README.rst b/session_redis/README.rst index 0479eae..f9bec36 100644 --- a/session_redis/README.rst +++ b/session_redis/README.rst @@ -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) diff --git a/session_redis/http.py b/session_redis/http.py index e2e1069..634fdbb 100644 --- a/session_redis/http.py +++ b/session_redis/http.py @@ -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,