diff --git a/config/settings/core.py b/config/settings/core.py index 9176c66..406b991 100644 --- a/config/settings/core.py +++ b/config/settings/core.py @@ -115,3 +115,13 @@ }, }, } + +CACHES = { + "default": { + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": config("CACHE_DB_URL"), + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + }, + } +} diff --git a/docker-compose.base.yaml b/docker-compose.base.yaml index 11dc0ce..e521454 100644 --- a/docker-compose.base.yaml +++ b/docker-compose.base.yaml @@ -30,6 +30,19 @@ services: interval: 2s timeout: 5s retries: 5 + redis: + restart: on-failure + container_name: food-anywhere-redis + image: redis:6.2-alpine + expose: + - "6379" + networks: + - main + healthcheck: + test: [ "CMD", "redis-cli", "ping" ] + interval: 2s + timeout: 5s + retries: 5 networks: main: diff --git a/docker-compose.prod.yaml b/docker-compose.prod.yaml index 64821b0..d5de2f1 100644 --- a/docker-compose.prod.yaml +++ b/docker-compose.prod.yaml @@ -17,6 +17,10 @@ services: file: docker-compose.base.yaml env_file: - envs/.env.prod + redis: + extends: + service: redis + file: docker-compose.base.yaml networks: main: diff --git a/docker-compose.yaml b/docker-compose.yaml index 1fef3fd..3568697 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -17,6 +17,10 @@ services: file: docker-compose.base.yaml env_file: - envs/.env.local + redis: + extends: + service: redis + file: docker-compose.base.yaml networks: main: diff --git a/envs/.env.local b/envs/.env.local index 2c61185..29d55e9 100644 --- a/envs/.env.local +++ b/envs/.env.local @@ -6,3 +6,6 @@ POSTGRES_PASSWORD=postgres POSTGRES_DB=food_anywhere_local POSTGRES_HOST=postgres POSTGRES_PORT=5432 + +# Redis +CACHE_DB_URL='redis://redis:6379/2' diff --git a/envs/.env.prod b/envs/.env.prod index 5174898..e055bd9 100644 --- a/envs/.env.prod +++ b/envs/.env.prod @@ -6,3 +6,6 @@ POSTGRES_PASSWORD=postgres POSTGRES_DB=food_anywhere_prod POSTGRES_HOST=postgres POSTGRES_PORT=5432 + +# Redis +CACHE_DB_URL='redis://redis:6379/2' diff --git a/requirements.txt b/requirements.txt index fa7e33e..6d7e3cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,7 @@ cfgv==3.4.0 click==8.1.7 distlib==0.3.8 Django==5.0.7 +django-redis==5.4.0 filelock==3.15.4 identify==2.6.0 iniconfig==2.0.0 @@ -20,5 +21,6 @@ pytest-django==4.8.0 pytest-env==1.1.3 python-decouple==3.8 PyYAML==6.0.1 +redis==5.0.8 sqlparse==0.5.1 virtualenv==20.26.3