Redis cache backend support limits and default configuration in Contao
0 reputation · 26 Nov 2021, 13:27 UTC
0 reputation · 26 Nov 2021, 13:27 UTC
Contao 4.x documents Redis as an optional cache backend, but the default configuration parameters are not fully specified. This leaves an unresolved decision about expected cache consistency across installations when Redis is enabled.
The goal is to clarify the documented behavior for Redis cache support and identify which settings determine cache hit and miss behavior by default, given that misconfiguration can lead to inconsistent cache behavior.
What configuration values are treated as defaults for the Redis cache backend in Contao? How does Contao select between file-based and Redis caching when both are configured? Which settings are required to achieve consistent cache behavior across installations?
34775 reputation · 26 Nov 2021, 22:34 UTC
In Contao 4.x, Redis integration is handled via the underlying Symfony Cache component. Because Redis is an optional backend, there are no "hard-coded" framework defaults for connection strings; instead, the system relies on the configuration provided in the environment files or YAML packages.
Contao does not automatically "switch" between file-based and Redis caching based on availability. The selection is explicit: if the framework.cache.app (or a specific cache pool) is configured to use the Redis adapter, Symfony will attempt to use it. If the Redis DSN is missing or the required PHP extension (phpredis) is not installed, the system will typically throw a service error rather than silently falling back to the filesystem, unless a fallback chain is explicitly defined in the configuration.
To ensure consistent behavior across multiple installations—especially when sharing a single Redis instance—you must explicitly define a unique namespace. Without this, different Contao installations will overwrite each other's keys, leading to unpredictable cache hits and misses.
The following settings are required for a stable, consistent Redis deployment:
redis://redis-server:6379).maxmemory-policy (such as allkeys-lru) to prevent the cache from crashing the server when full.To verify which adapter is currently active and whether Redis is receiving traffic, use these commands:
# Check the active container services
bin/console debug:container | grep cache
# Monitor Redis traffic in real-time
redis-cli monitor
To provide a more specific configuration snippet, please specify the exact version of Contao 4.x you are using, as the transition between Symfony 4 and 5 changed the YAML syntax for cache pools.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.