Skip to content

Commit abb690d

Browse files
committed
Add Redis support
1 parent cae3c54 commit abb690d

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

myproject/settings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@
5454
TRUSTED_USER_DOMAIN_HTTPS_443_DEFAULT = f"https://{domain}"
5555
CSRF_TRUSTED_ORIGINS.extend([TRUSTED_USER_DOMAIN_HTTP, TRUSTED_USER_DOMAIN_HTTPS, TRUSTED_USER_DOMAIN_HTTP_80_DEFAULT, TRUSTED_USER_DOMAIN_HTTPS_443_DEFAULT])
5656

57+
# Caching via Redis
58+
REDIS_HOST = os.environ.get("REDIS_HOST", "")
59+
REDIS_PORT = os.environ.get("REDIS_PORT", "6379")
60+
REDIS_DB = os.environ.get("REDIS_DB", "0")
61+
62+
if REDIS_HOST:
63+
CACHES = {
64+
"default": {
65+
"BACKEND": "django_redis.cache.RedisCache",
66+
"OPTIONS": {
67+
"LOCATION": "redis://%s:%s/%s" % (REDIS_HOST, REDIS_PORT, REDIS_DB),
68+
"PASSWORD": os.environ.get("REDIS_PASSWORD", ""),
69+
}
70+
}
71+
}
72+
73+
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
74+
SESSION_CACHE_ALIAS = "default"
75+
5776
#Session Management
5877
CSRF_COOKIE_HTTPONLY = True
5978
SESSION_EXPIRE_AT_BROWSER_CLOSE = os.environ.get('SESSION_EXPIRE_AT_BROWSER_CLOSE', 'True').lower() in ['true']

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ josepy==1.5.0
2121
# APP SPECIFIC
2222
django-storages==1.14.6
2323
boto3==1.42.5
24+
django-redis==6.0.0

0 commit comments

Comments
 (0)