pantheon-systems / wp-redis

WordPress Object Cache using Redis.
https://wordpress.org/plugins/wp-redis/
GNU General Public License v2.0
226 stars 68 forks source link

Support Setting the Database Instance via an Environment Variable #272

Closed timnolte closed 4 years ago

timnolte commented 4 years ago

This would be in order to support multiple servers connecting to the same Redis instance. Using just the WP_CACHE_KEY_SALT is not enough when you end up calling the wp_flush_cache() method as it will remove everything in the DB instance not just those items with the specified WP_CACHE_KEY_SALT.

timnolte commented 4 years ago

You mention using

$redis_server = array(
     'host'     => '127.0.0.1',
     'port'     => 6379,
     'auth'     => '12345',
     'database' => 0, // Optionally use a specific numeric Redis database. Default is 0.
 );

when not on Pantheon but it's just as easy to use/setup the Pantheon environment variables when using a VPS. In the code you aren't allowing for the selection of a database, with a fallback default, to make this usable without that custom code. I can't use that custom code when using a Composer-based managed WordPress instance.

timnolte commented 4 years ago

So as I was going back to check any other cases where the $redis_server array was being used I discovered that there is a filter that could be used in this case wp_redis_prepare_client_connection_callback