From d60d370ddf58b6d5b63dc6eda97c0a291e580087 Mon Sep 17 00:00:00 2001 From: Dan LaManna Date: Tue, 3 Sep 2024 16:13:02 -0400 Subject: [PATCH] Add support for testing against the builtin redis backend --- cachalot/settings.py | 1 + docs/quickstart.rst | 2 ++ settings.py | 12 ++++++++++++ tox.ini | 25 +++++++++++++------------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/cachalot/settings.py b/cachalot/settings.py index 2bf5c817a..6cb603855 100644 --- a/cachalot/settings.py +++ b/cachalot/settings.py @@ -30,6 +30,7 @@ 'django.core.cache.backends.dummy.DummyCache', 'django.core.cache.backends.locmem.LocMemCache', 'django.core.cache.backends.filebased.FileBasedCache', + 'django.core.cache.backends.redis.RedisCache', 'django_redis.cache.RedisCache', 'django.core.cache.backends.memcached.MemcachedCache', 'django.core.cache.backends.memcached.PyLibMCCache', diff --git a/docs/quickstart.rst b/docs/quickstart.rst index a86198c03..507cd1e36 100644 --- a/docs/quickstart.rst +++ b/docs/quickstart.rst @@ -9,6 +9,8 @@ Requirements - a cache configured as ``'default'`` with one of these backends: - `django-redis `_ + - `redis `_ + (requires Django >= 4) - `memcached `_ (using either python-memcached or pylibmc) - `filebased `_ diff --git a/settings.py b/settings.py index 19d75600d..1595fa4e7 100644 --- a/settings.py +++ b/settings.py @@ -72,6 +72,18 @@ } } +try: + from django.core.cache.backends.redis import RedisCache +except ImportError: + pass +else: + CACHES['builtin_redis']= { + 'BACKEND': 'django.core.cache.backends.redis.RedisCache', + # Make sure to use a different redis database to avoid conflicts with the other + # redis cache backend. + 'LOCATION': 'redis://127.0.0.1:6379/1', + } + try: import pylibmc except ImportError: diff --git a/tox.ini b/tox.ini index fb07fc636..949ea34f5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] envlist = py{37,38,39,310}-django3.2-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased}, - py{38,39,310}-django4.1-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased}, - py{38,39,310,312}-django4.2-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased}, - py{310,311,312}-django5.0-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased}, - py{310,311,312}-djangomain-{sqlite3,postgresql,mysql}-{redis,memcached,pylibmc,locmem,filebased}, + py{38,39,310}-django4.1-{sqlite3,postgresql,mysql}-{builtin_redis,redis,memcached,pylibmc,locmem,filebased}, + py{38,39,310,312}-django4.2-{sqlite3,postgresql,mysql}-{builtin_redis,redis,memcached,pylibmc,locmem,filebased}, + py{310,311,312}-django5.0-{sqlite3,postgresql,mysql}-{builtin_redis,redis,memcached,pylibmc,locmem,filebased}, + py{310,311,312}-djangomain-{sqlite3,postgresql,mysql}-{builtin_redis,redis,memcached,pylibmc,locmem,filebased}, [testenv] passenv = * @@ -35,14 +35,15 @@ deps = beautifulsoup4 coverage setenv = - sqlite3: DB_ENGINE=sqlite3 - postgresql: DB_ENGINE=postgresql - mysql: DB_ENGINE=mysql - locmem: CACHE_BACKEND=locmem - filebased: CACHE_BACKEND=filebased - redis: CACHE_BACKEND=redis - memcached: CACHE_BACKEND=memcached - pylibmc: CACHE_BACKEND=pylibmc + sqlite3: DB_ENGINE=sqlite3 + postgresql: DB_ENGINE=postgresql + mysql: DB_ENGINE=mysql + locmem: CACHE_BACKEND=locmem + filebased: CACHE_BACKEND=filebased + redis: CACHE_BACKEND=redis + builtin_redis: CACHE_BACKEND=builtin_redis + memcached: CACHE_BACKEND=memcached + pylibmc: CACHE_BACKEND=pylibmc commands = coverage run -a --source=cachalot ./runtests.py