I'm putting this here because it took me a long while to figure this out.
I wanted to improve WordPress's performance by using Redis object caching. My environment is defined in a docker compose.
version: '3.6' services: redis: image: 'redis:alpine' ports: - '6379:6379' restart: always expose: - '6379' wordpress: image: 'wordpress:latest'
There is a handy WordPress plugin for that, but of course, it needs redis to be installed and configured properly. That's the part I struggled with as it could not connect to my redis container.
Normally, Redis should work out-of-the-box with WordPress as long as it is accessible via localhost:6379.
The thing is, in a docker setup the redis instance is accessible via its container name.
So in the above example, in order for WordPress to find it, you need to modify the constant
WP_REDIS_HOST to "redis" in your wp-config.php file.
define('WP_REDIS_HOST', 'redis'); define('WP_REDIS_PORT', '6379');
Additional constants are available. More information is available here.
That's it, really. I hope this helps someone.
Top comments (0)