-
-
Notifications
You must be signed in to change notification settings - Fork 656
Added django-redis as default cache #1371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
7b5ebe7
85d540c
5dcbe56
10658fa
3b8b247
17e9bef
385910a
b8c287b
78209e9
3bc55d6
6793f43
4bfab11
85b2e78
38e66b8
a890913
ae0b510
95f4868
ebefc2c
f720002
f89ef94
9ab9f10
8061bdb
e17b798
94c2b5e
60287ec
a96a907
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -122,11 +122,20 @@ class Base(Configuration): | |||||||||||||||||||||||||||||||||||
| "INDEX_PREFIX": ENVIRONMENT.lower(), | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| REDIS_HOST = values.SecretValue(environ_name="REDIS_HOST") | ||||||||||||||||||||||||||||||||||||
| REDIS_PASSWORD = values.SecretValue(environ_name="REDIS_PASSWORD") | ||||||||||||||||||||||||||||||||||||
| REDIS_PORT = values.SecretValue(environ_name="REDIS_PORT") | ||||||||||||||||||||||||||||||||||||
| CACHES = { | ||||||||||||||||||||||||||||||||||||
| "default": { | ||||||||||||||||||||||||||||||||||||
| "BACKEND": "django.core.cache.backends.locmem.LocMemCache", | ||||||||||||||||||||||||||||||||||||
| "BACKEND": "django_redis.cache.RedisCache", | ||||||||||||||||||||||||||||||||||||
| "LOCATION": f"redis://:{REDIS_PASSWORD}@{REDIS_HOST}:{REDIS_PORT}", | ||||||||||||||||||||||||||||||||||||
| "OPTIONS": { | ||||||||||||||||||||||||||||||||||||
| "CLIENT_CLASS": "django_redis.client.DefaultClient", | ||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||
| "TIMEOUT": 300, | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+127
to
135
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redis cache configuration needs improvement. The Redis cache configuration is functional but has some issues to address:
Apply the following changes to fix the naming inconsistency and add recommended settings: CACHES = {
"default": {
"BACKEND": "django_redis.cache.RedisCache",
- "LOCATION": values.SecretValue(environ_name="REDIS_URL"),
+ "LOCATION": values.SecretValue(environ_name="DJANGO_REDIS_URL"),
"OPTIONS": {
"CLIENT_CLASS": "django_redis.client.DefaultClient",
+ "IGNORE_EXCEPTIONS": True, # Prevents cache-related exceptions from breaking the site
},
+ "TIMEOUT": 300, # 5 minutes default timeout
}
}📝 Committable suggestion
Suggested change
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Rajgupta36 could you take a look at these extra configuration params -- some of them may be userful.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| # Database | ||||||||||||||||||||||||||||||||||||
| # https://docs.djangoproject.com/en/5.1/ref/settings/#databases | ||||||||||||||||||||||||||||||||||||
| DATABASES = { | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,7 @@ pygoat | |
| pymdownx | ||
| pyyaml | ||
| repositorycontributor | ||
| requirepass | ||
| rsc | ||
| saft | ||
| sakanashi | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,37 +4,56 @@ services: | |
| image: arkid15r/owasp-nest-backend:production | ||
| env_file: .env.backend | ||
| depends_on: | ||
| production-nest-cache: | ||
| condition: service_healthy | ||
| production-nest-db: | ||
| condition: service_healthy | ||
| restart: unless-stopped | ||
| networks: | ||
| - nest-app-network | ||
| - nest-cache-network | ||
| - nest-db-network | ||
| volumes: | ||
| - ./data:/home/owasp/data | ||
|
|
||
| production-nest-frontend: | ||
| container_name: production-nest-frontend | ||
| image: arkid15r/owasp-nest-frontend:production | ||
| production-nest-cache: | ||
| container_name: production-nest-cache | ||
| image: redis:7.2.7-alpine3.21 | ||
| command: redis-server --requirepass nest_redis_production --maxmemory 25mb --maxmemory-policy allkeys-lru | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems this configuration uses plain text password to run the server. There is no point in a password if it's a known piece of information. |
||
| healthcheck: | ||
| interval: 5s | ||
| retries: 5 | ||
| test: [CMD, redis-cli, -a, nest_redis_production, ping] | ||
| timeout: 5s | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./volumes/cache:/data | ||
| networks: | ||
| - nest-app-network | ||
| - nest-cache-network | ||
|
|
||
| production-nest-db: | ||
| container_name: production-nest-db | ||
| image: postgres:16.4 | ||
| env_file: .env.db | ||
| healthcheck: | ||
| test: [CMD, pg_isready, -U, nest_user_production, -d, nest_db_production] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 5 | ||
| test: [CMD, pg_isready, -U, nest_user_production, -d, nest_db_production] | ||
| timeout: 5s | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./volumes/db:/var/lib/postgresql/data | ||
| networks: | ||
| - nest-db-network | ||
|
|
||
| production-nest-frontend: | ||
| container_name: production-nest-frontend | ||
| image: arkid15r/owasp-nest-frontend:production | ||
| restart: unless-stopped | ||
| networks: | ||
| - nest-app-network | ||
|
|
||
| networks: | ||
| nest-app-network: | ||
| nest-cache-network: | ||
| nest-db-network: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,37 +4,56 @@ services: | |
| image: arkid15r/owasp-nest-backend:staging | ||
| env_file: .env.backend | ||
| depends_on: | ||
| staging-nest-cache: | ||
| condition: service_healthy | ||
| staging-nest-db: | ||
| condition: service_healthy | ||
| restart: unless-stopped | ||
| networks: | ||
| - nest-app-network | ||
| - nest-cache-network | ||
| - nest-db-network | ||
| volumes: | ||
| - ./data:/home/owasp/data | ||
|
|
||
| staging-nest-frontend: | ||
| container_name: staging-nest-frontend | ||
| image: arkid15r/owasp-nest-frontend:staging | ||
| staging-nest-cache: | ||
| container_name: staging-nest-cache | ||
| image: redis:7.2.7-alpine3.21 | ||
| command: redis-server --requirepass nest-cache-staging --maxmemory 25mb --maxmemory-policy allkeys-lru | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, this is bad -- it's a plain text password in both staging/prod. This has to be done at via .env files and/or |
||
| healthcheck: | ||
| interval: 5s | ||
| retries: 5 | ||
| test: [CMD, redis-cli, -a, nest-cache-staging, ping] | ||
| timeout: 5s | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./volumes/cache:/data | ||
| networks: | ||
| - nest-app-network | ||
| - nest-cache-network | ||
|
|
||
| staging-nest-db: | ||
| container_name: staging-nest-db | ||
| image: postgres:16.4 | ||
| env_file: .env.db | ||
| healthcheck: | ||
| test: [CMD, pg_isready, -U, nest_user_staging, -d, nest_db_staging] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 5 | ||
| test: [CMD, pg_isready, -U, nest_user_staging, -d, nest_db_staging] | ||
| timeout: 5s | ||
| restart: unless-stopped | ||
| volumes: | ||
| - ./volumes/db:/var/lib/postgresql/data | ||
| networks: | ||
| - nest-db-network | ||
|
|
||
| staging-nest-frontend: | ||
| container_name: staging-nest-frontend | ||
| image: arkid15r/owasp-nest-frontend:staging | ||
| restart: unless-stopped | ||
| networks: | ||
| - nest-app-network | ||
|
|
||
| networks: | ||
| nest-app-network: | ||
| nest-cache-network: | ||
| nest-db-network: | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be static
6379