Skip to content

Commit

Permalink
Add redis integration for django-cachalot
Browse files Browse the repository at this point in the history
  • Loading branch information
danlamanna committed Aug 29, 2024
1 parent 2aad400 commit 0b2d026
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions dev/.env.docker-compose
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey
DJANGO_STORAGE_BUCKET_NAME=django-storage
DJANGO_MINIO_STORAGE_MEDIA_URL=http://localhost:9000/django-storage
DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@elasticsearch:9200
DJANGO_ISIC_REDIS_URL=redis://localhost:6379
DJANGO_ISIC_DATACITE_USERNAME="fakeuser"
DJANGO_ISIC_DATACITE_PASSWORD="fakepassword"
1 change: 1 addition & 0 deletions dev/.env.docker-compose-native
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ DJANGO_MINIO_STORAGE_ACCESS_KEY=minioAccessKey
DJANGO_MINIO_STORAGE_SECRET_KEY=minioSecretKey
DJANGO_STORAGE_BUCKET_NAME=django-storage
DJANGO_ISIC_ELASTICSEARCH_URI=http://elastic:elastic@localhost:9200
DJANGO_ISIC_REDIS_URL=redis://localhost:6379
DJANGO_ISIC_DATACITE_USERNAME="fakeuser"
DJANGO_ISIC_DATACITE_PASSWORD="fakepassword"
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ services:
ZS_LISTFILE_BASIC_AUTH: "insecurezipdownloadauthtoken"
ports:
- 4008:4008

redis:
image: redis:latest
ports:
- ${DOCKER_REDIS_PORT-6379}:6379


redisinsight:
image: redis/redisinsight:latest
ports:
- ${DOCKER_REDIS_INSIGHT_PORT-5540}:5540
18 changes: 18 additions & 0 deletions isic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
TestingBaseConfiguration,
)
from configurations import values
from django_cache_url import BACKENDS


def _oauth2_pkce_required(client_id):
Expand All @@ -22,6 +23,19 @@ def _oauth2_pkce_required(client_id):
return oauth_application.client_type != OAuth2Application.CLIENT_CONFIDENTIAL


# This is an unfortunate monkeypatching of django_cache_url to support an old version
# of django-redis on a newer version of django.
# See https://github.com/noripyt/django-cachalot/issues/222 for fixing this.
BACKENDS["redis"] = BACKENDS["rediss"] = "django_redis.cache.RedisCache"


class CacheURLValue(values.DictBackendMixin, values.CastingMixin, values.Value):
caster = "django_cache_url.parse"
message = "Cannot interpret cache URL value {0!r}"
environ_name = "CACHE_URL"
late_binding = True


class IsicMixin(ConfigMixin):
WSGI_APPLICATION = "isic.wsgi.application"
ROOT_URLCONF = "isic.urls"
Expand Down Expand Up @@ -122,6 +136,8 @@ def mutate_configuration(configuration: ComposedConfiguration) -> None:
ISIC_SANDBOX_BANNER = values.BooleanValue(False)
ISIC_PLACEHOLDER_IMAGES = values.BooleanValue(False)

CACHES = CacheURLValue(environ_name="ISIC_REDIS_URL", environ_prefix="DJANGO_")

ISIC_ELASTICSEARCH_URI = values.SecretValue()
ISIC_ELASTICSEARCH_INDEX = "isic"
ISIC_GUI_URL = "https://www.isic-archive.com/"
Expand Down Expand Up @@ -248,6 +264,8 @@ class HerokuProductionConfiguration(IsicMixin, HerokuProductionBaseConfiguration
ISIC_DATACITE_DOI_PREFIX = "10.34970"
ISIC_ELASTICSEARCH_URI = values.SecretValue(environ_name="SEARCHBOX_URL", environ_prefix=None)

CACHES = CacheURLValue(environ_name="STACKHERO_REDIS_URL_TLS", environ_prefix=None)

AWS_CLOUDFRONT_KEY = values.SecretValue()
AWS_CLOUDFRONT_KEY_ID = values.Value()
AWS_S3_CUSTOM_DOMAIN = values.Value()
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
"pydantic",
"pymongo",
"pyparsing",
"redis",
"hiredis",
"django-redis",
"python-magic",
"requests",
"sentry-sdk[pure_eval]",
Expand Down
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ passenv =
DJANGO_MINIO_STORAGE_ENDPOINT
DJANGO_MINIO_STORAGE_SECRET_KEY
DJANGO_ISIC_ELASTICSEARCH_URI
DJANGO_ISIC_REDIS_URL
extras =
dev
deps =
Expand Down Expand Up @@ -91,6 +92,7 @@ passenv =
DJANGO_MINIO_STORAGE_ENDPOINT
DJANGO_MINIO_STORAGE_SECRET_KEY
DJANGO_ISIC_ELASTICSEARCH_URI
DJANGO_ISIC_REDIS_URL
extras =
dev
install_command = pip install --find-links https://girder.github.io/large_image_wheels {opts} {packages}
Expand Down

0 comments on commit 0b2d026

Please sign in to comment.