Redis Provider¶
The Redis provider requires the [redis] extra to be installed.
Installation¶
Auto-Detection¶
The provider activates automatically from any of these settings:
| Setting | Detected when |
|---|---|
CACHES[*]['BACKEND'] |
Contains redis |
CELERY_BROKER_URL |
Starts with redis:// |
SESSION_ENGINE |
Contains redis |
Minimal Setup¶
settings.py
TEST_RUNNER = 'django_testcontainers_plus.runner.TestcontainersRunner'
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.redis.RedisCache',
'LOCATION': 'redis://localhost:6379/0',
}
}
CELERY_BROKER_URL = 'redis://localhost:6379/0'
A single Redis container serves both the cache and the Celery broker.
Default Container¶
| Property | Value |
|---|---|
| Image | redis:7-alpine |
| Port | Randomly assigned by Docker |
Configuration Options¶
settings.py
TESTCONTAINERS = {
'redis': {
'image': 'redis:7-alpine',
'environment': {
'REDIS_ARGS': '--maxmemory 256mb',
},
}
}
Settings Injection¶
After the Redis container starts, the provider updates your settings automatically:
CACHES[*]['LOCATION']→ updated to the container's URLCELERY_BROKER_URL→ updated to the container's URLCELERY_RESULT_BACKEND→ updated to the container's URL
Custom settings updates
If you need full control over which settings are updated, you can provide a custom
update_settings dict in your config: