From 243082697016cf38b2b0aa9b8104a510d22711ad Mon Sep 17 00:00:00 2001 From: Samuel Cattini-Schultz Date: Sat, 1 Jun 2024 14:36:58 +1000 Subject: [PATCH] Use redis instead of memcached --- compose.yaml | 6 +++-- config/dev/django.env | 4 +-- osuchan/settings.py | 11 +++++--- poetry.lock | 60 ++++++++++++++++++++++++++++++++++--------- pyproject.toml | 2 +- 5 files changed, 62 insertions(+), 21 deletions(-) diff --git a/compose.yaml b/compose.yaml index 8147cfa..6ace531 100644 --- a/compose.yaml +++ b/compose.yaml @@ -5,7 +5,7 @@ volumes: prometheus-data: grafana-data: beatmaps: - redis-data: + cache-data: difficalcy-cache-data: secrets: @@ -29,7 +29,9 @@ services: - queue-data:/var/lib/rabbitmq:rw cache: - image: memcached:1 + image: redis:7 + volumes: + - cache-data:/data api: build: . diff --git a/config/dev/django.env b/config/dev/django.env index f0e8ced..0ec4c13 100644 --- a/config/dev/django.env +++ b/config/dev/django.env @@ -10,8 +10,8 @@ POSTGRES_DB_PASSWORD="osuchan" POSTGRES_DB_HOST="db" POSTGRES_DB_PORT="5432" -MEMCACHED_HOST="cache" -MEMCACHED_PORT="11211" +REDIS_HOST="cache" +REDIS_PORT="6379" CELERY_USER="osuchan" CELERY_PASSWORD="osuchan" diff --git a/osuchan/settings.py b/osuchan/settings.py index 31969e7..2a58d5f 100644 --- a/osuchan/settings.py +++ b/osuchan/settings.py @@ -18,8 +18,8 @@ class EnvSettings(BaseSettings): POSTGRES_DB_PASSWORD: str POSTGRES_DB_HOST: str POSTGRES_DB_PORT: str - MEMCACHED_HOST: str - MEMCACHED_PORT: str + REDIS_HOST: str + REDIS_PORT: str CELERY_USER: str CELERY_PASSWORD: str CELERY_HOST: str @@ -183,8 +183,11 @@ class EnvSettings(BaseSettings): CACHES = { "default": { - "BACKEND": "django_prometheus.cache.backends.memcached.PyMemcacheCache", - "LOCATION": f"{env_settings.MEMCACHED_HOST}:{env_settings.MEMCACHED_PORT}", + "BACKEND": "django_redis.cache.RedisCache", + "LOCATION": f"redis://{env_settings.REDIS_HOST}:{env_settings.REDIS_PORT}/0", + "OPTIONS": { + "CLIENT_CLASS": "django_redis.client.DefaultClient", + }, } } diff --git a/poetry.lock b/poetry.lock index 029ccd2..3347532 100644 --- a/poetry.lock +++ b/poetry.lock @@ -64,6 +64,17 @@ typing-extensions = {version = ">=4", markers = "python_version < \"3.11\""} [package.extras] tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] +[[package]] +name = "async-timeout" +version = "4.0.3" +description = "Timeout context manager for asyncio programs" +optional = false +python-versions = ">=3.7" +files = [ + {file = "async-timeout-4.0.3.tar.gz", hash = "sha256:4640d96be84d82d02ed59ea2b7105a0f7b33abe8703703cd0ab0bf87c427522f"}, + {file = "async_timeout-4.0.3-py3-none-any.whl", hash = "sha256:7405140ff1230c310e51dc27b3145b9092d659ce68ff733fb0cefe3ee42be028"}, +] + [[package]] name = "billiard" version = "4.2.0" @@ -474,6 +485,24 @@ files = [ [package.dependencies] prometheus-client = ">=0.7" +[[package]] +name = "django-redis" +version = "5.4.0" +description = "Full featured redis cache backend for Django." +optional = false +python-versions = ">=3.6" +files = [ + {file = "django-redis-5.4.0.tar.gz", hash = "sha256:6a02abaa34b0fea8bf9b707d2c363ab6adc7409950b2db93602e6cb292818c42"}, + {file = "django_redis-5.4.0-py3-none-any.whl", hash = "sha256:ebc88df7da810732e2af9987f7f426c96204bf89319df4c6da6ca9a2942edd5b"}, +] + +[package.dependencies] +Django = ">=3.2" +redis = ">=3,<4.0.0 || >4.0.0,<4.0.1 || >4.0.1" + +[package.extras] +hiredis = ["redis[hiredis] (>=3,!=4.0.0,!=4.0.1)"] + [[package]] name = "djangorestframework" version = "3.15.1" @@ -1050,17 +1079,6 @@ python-dotenv = ">=0.21.0" toml = ["tomli (>=2.0.1)"] yaml = ["pyyaml (>=6.0.1)"] -[[package]] -name = "pymemcache" -version = "4.0.0" -description = "A comprehensive, fast, pure Python memcached client" -optional = false -python-versions = ">=3.7" -files = [ - {file = "pymemcache-4.0.0-py2.py3-none-any.whl", hash = "sha256:f507bc20e0dc8d562f8df9d872107a278df049fa496805c1431b926f3ddd0eab"}, - {file = "pymemcache-4.0.0.tar.gz", hash = "sha256:27bf9bd1bbc1e20f83633208620d56de50f14185055e49504f4f5e94e94aff94"}, -] - [[package]] name = "pytest" version = "8.2.1" @@ -1140,6 +1158,24 @@ files = [ {file = "pytz-2024.1.tar.gz", hash = "sha256:2a29735ea9c18baf14b448846bde5a48030ed267578472d8955cd0e7443a9812"}, ] +[[package]] +name = "redis" +version = "5.0.4" +description = "Python client for Redis database and key-value store" +optional = false +python-versions = ">=3.7" +files = [ + {file = "redis-5.0.4-py3-none-any.whl", hash = "sha256:7adc2835c7a9b5033b7ad8f8918d09b7344188228809c98df07af226d39dec91"}, + {file = "redis-5.0.4.tar.gz", hash = "sha256:ec31f2ed9675cc54c21ba854cfe0462e6faf1d83c8ce5944709db8a4700b9c61"}, +] + +[package.dependencies] +async-timeout = {version = ">=4.0.3", markers = "python_full_version < \"3.11.3\""} + +[package.extras] +hiredis = ["hiredis (>=1.0.0)"] +ocsp = ["cryptography (>=36.0.1)", "pyopenssl (==20.0.1)", "requests (>=2.26.0)"] + [[package]] name = "requests" version = "2.32.3" @@ -1379,4 +1415,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "e7c39327521bf160eb48642640a52cafd86bf1fd4a12b08ade24dc06696218bc" +content-hash = "d80cf46ff8e84ade39b7170ca705e92dd13f5dffc613d0c3bc1167627bed15bd" diff --git a/pyproject.toml b/pyproject.toml index 950d556..778725d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,13 +16,13 @@ gunicorn = "^22.0.0" httpx = "^0.27.0" oppaipy = "^1.0.4" psycopg2-binary = "^2.9.1" -pymemcache = "^4.0.0" requests = "^2.25.1" rosu-pp-py = "^1.0.0" tqdm = "^4.64.0" flower = "^2.0.0" pydantic-settings = "^2.0.0" django-prometheus = "^2.3.1" +django-redis = "^5.4.0" [tool.poetry.group.dev.dependencies] black = "^24.4.2"