From 7afc8a6cd9afba962554904bdcaf29e21206238c Mon Sep 17 00:00:00 2001 From: Samuel Paccoud - FUN MOOC Date: Tue, 11 Dec 2018 16:32:27 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8(session)=20add=20redis=20as=20session?= =?UTF-8?q?=20backend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Redis is in our opinion the best practice to record sessions as it combines the speed of memory with a persistence layer. --- config/cms/docker_run_production.py | 19 ++++++++++++++++--- config/lms/docker_run_production.py | 16 ++++++++++++++-- docker-compose.yml | 5 +++++ requirements.txt | 1 + 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/config/cms/docker_run_production.py b/config/cms/docker_run_production.py index 59512613..77a556fb 100644 --- a/config/cms/docker_run_production.py +++ b/config/cms/docker_run_production.py @@ -157,9 +157,8 @@ SESSION_COOKIE_HTTPONLY = config( "SESSION_COOKIE_HTTPONLY", default=True, formatter=bool ) -SESSION_ENGINE = config( - "SESSION_ENGINE", default="django.contrib.sessions.backends.cache" -) +SESSION_ENGINE = config("SESSION_ENGINE", default="redis_sessions.session") + SESSION_COOKIE_SECURE = config( "SESSION_COOKIE_SECURE", default=SESSION_COOKIE_SECURE, formatter=bool ) @@ -167,6 +166,20 @@ "SESSION_SAVE_EVERY_REQUEST", default=SESSION_SAVE_EVERY_REQUEST, formatter=bool ) +SESSION_REDIS = config( + "SESSION_REDIS", + default={ + "host": "redis", + "port": 6379, + "db": 1, # db 0 is used for Celery Broker + "password": "", + "prefix": "session", + "socket_timeout": 1, + "retry_on_timeout": False, + }, + formatter=json.loads, +) + # social sharing settings SOCIAL_SHARING_SETTINGS = config( "SOCIAL_SHARING_SETTINGS", default=SOCIAL_SHARING_SETTINGS, formatter=json.loads diff --git a/config/lms/docker_run_production.py b/config/lms/docker_run_production.py index a5c2e59d..f8106dd2 100644 --- a/config/lms/docker_run_production.py +++ b/config/lms/docker_run_production.py @@ -33,8 +33,20 @@ DEBUG = False DEFAULT_TEMPLATE_ENGINE["OPTIONS"]["debug"] = False -SESSION_ENGINE = config( - "SESSION_ENGINE", default="django.contrib.sessions.backends.cache" +SESSION_ENGINE = config("SESSION_ENGINE", default="redis_sessions.session") + +SESSION_REDIS = config( + "SESSION_REDIS", + default={ + "host": "redis", + "port": 6379, + "db": 1, # db 0 is used for Celery Broker + "password": "", + "prefix": "session", + "socket_timeout": 1, + "retry_on_timeout": False, + }, + formatter=json.loads, ) # IMPORTANT: With this enabled, the server must always be behind a proxy that diff --git a/docker-compose.yml b/docker-compose.yml index 1a0b318c..eb1b7ac4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,6 +18,9 @@ services: memcached: image: memcached:1.4 + redis: + image: redis:4.0 + mailcatcher: image: sj26/mailcatcher:latest ports: @@ -44,6 +47,7 @@ services: - mysql - mongodb - memcached + - redis user: ${UID}:${GID} lms-dev: @@ -72,6 +76,7 @@ services: - mysql - mongodb - memcached + - redis cms: image: edxapp:latest diff --git a/requirements.txt b/requirements.txt index 3631567b..7d48bf52 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ configurable_lti_consumer-xblock==1.0.0-rc.1 # ==== third-party apps ==== raven==6.9.0 +django-redis-sessions==0.6.1