Skip to content

Exit the script early if the class doesn't exist, or it's been manually disabled. #468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
11 changes: 10 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
* can use this to guarantee uniqueness for the keys generated by this object cache.
*/

if ( ! defined( 'WP_REDIS_USE_RELAY' ) ) {
define( 'WP_REDIS_USE_RELAY', false );
}

// Conditionally run the script if: the correct class exists, and the script has not been disabled.
if ( ! class_exists( WP_REDIS_USE_RELAY ? 'Relay\Relay' : 'Redis' ) && ( defined( 'WP_REDIS_DISABLED' ) && WP_REDIS_DISABLED ) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this have an || in the middle?

if ( ! class_exists( WP_REDIS_USE_RELAY ? 'Relay\Relay' : 'Redis' ) || ( defined( 'WP_REDIS_DISABLED' ) && WP_REDIS_DISABLED ) ) {

In other words, if the class doesn't exist or WP Redis is disabled, then return.

return;
}

if ( ! defined( 'WP_CACHE_KEY_SALT' ) ) {
define( 'WP_CACHE_KEY_SALT', '' );
}
Expand Down Expand Up @@ -1298,7 +1307,7 @@ public function build_client_parameters( $redis_server ) {
* @return Redis Redis client.
*/
public function prepare_client_connection( $client_parameters ) {
if ( defined( 'WP_REDIS_USE_RELAY' ) && WP_REDIS_USE_RELAY ) {
if ( WP_REDIS_USE_RELAY ) {
$redis = new Relay\Relay();
} else {
$redis = new Redis();
Expand Down
Loading