Skip to content

Commit

Permalink
✨(session) add redis as session backend
Browse files Browse the repository at this point in the history
Redis is in our opinion the best practice to record sessions as
it combines the speed of memory with a persistence layer.
  • Loading branch information
sampaccoud committed Dec 11, 2018
1 parent 92d86c7 commit 7afc8a6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
19 changes: 16 additions & 3 deletions config/cms/docker_run_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,29 @@
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
)
SESSION_SAVE_EVERY_REQUEST = config(
"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
Expand Down
16 changes: 14 additions & 2 deletions config/lms/docker_run_production.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ services:
memcached:
image: memcached:1.4

redis:
image: redis:4.0

mailcatcher:
image: sj26/mailcatcher:latest
ports:
Expand All @@ -44,6 +47,7 @@ services:
- mysql
- mongodb
- memcached
- redis
user: ${UID}:${GID}

lms-dev:
Expand Down Expand Up @@ -72,6 +76,7 @@ services:
- mysql
- mongodb
- memcached
- redis

cms:
image: edxapp:latest
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7afc8a6

Please sign in to comment.