diff --git a/index-wp-redis.php b/index-wp-redis.php index e0e57802ced61b1b71be93a020673f56a5811ed2..6078c12f17288c051f49cc6ddd90e75ee4c3ac5b 100644 --- a/index-wp-redis.php +++ b/index-wp-redis.php @@ -196,9 +196,12 @@ function wp_redis_cache_connect_redis() { } $redis = new Redis(); - $redis->connect( $wp_redis_cache_config['redis_server'], $wp_redis_cache_config['redis_port'] ); - $redis->select( $wp_redis_cache_config['redis_db'] ); + + // Default DB is 0, so only need to SELECT if other + if ( $wp_redis_cache_config['redis_db'] ) { + $redis->select( $wp_redis_cache_config['redis_db'] ); + } // Fallback to predis5.2.php } else { if ( $wp_redis_cache_config['debug'] ) { @@ -206,11 +209,17 @@ function wp_redis_cache_connect_redis() { } include_once dirname( __FILE__ ) . '/wp-content/plugins/wp-redis-cache/predis5.2.php'; //we need this to use Redis inside of PHP - $redis = new Predis_Client( array( - 'host' => $wp_redis_cache_config['redis_server'], - 'port' => $wp_redis_cache_config['redis_port'], - 'database' => $wp_redis_cache_config['redis_db'], - ) ); + $redis = array( + 'host' => $wp_redis_cache_config['redis_server'], + 'port' => $wp_redis_cache_config['redis_port'], + ); + + // Default DB is 0, so only need to SELECT if other + if ( $wp_redis_cache_config['redis_db'] ) { + $redis['database'] = $wp_redis_cache_config['redis_db']; + } + + $redis = new Predis_Client( $redis ); } return $redis; diff --git a/wp-redis-cache/wp-redis-cache.php b/wp-redis-cache/wp-redis-cache.php index 4da7a70a7d8a93de3e4dd201b5bbc219f753e0d1..ffb214d761c0e31487b0e5fa282b1ce98bd93201 100644 --- a/wp-redis-cache/wp-redis-cache.php +++ b/wp-redis-cache/wp-redis-cache.php @@ -134,17 +134,16 @@ class WP_Redis_Cache { $redis_settings = array( 'host' => '127.0.0.1', 'port' => 6379, - 'database' => 0, ); // Override default connection settings with global values, when present - if ( defined( 'WP_REDIS_CACHE_REDIS_HOST' ) ) { + if ( defined( 'WP_REDIS_CACHE_REDIS_HOST' ) && WP_REDIS_CACHE_REDIS_HOST ) { $redis_settings['host'] = WP_REDIS_CACHE_REDIS_HOST; } - if ( defined( 'WP_REDIS_CACHE_REDIS_PORT' ) ) { + if ( defined( 'WP_REDIS_CACHE_REDIS_PORT' ) && WP_REDIS_CACHE_REDIS_PORT ) { $redis_settings['port'] = WP_REDIS_CACHE_REDIS_PORT; } - if ( defined( 'WP_REDIS_CACHE_REDIS_DB' ) ) { + if ( defined( 'WP_REDIS_CACHE_REDIS_DB' ) && WP_REDIS_CACHE_REDIS_DB ) { $redis_settings['database'] = WP_REDIS_CACHE_REDIS_DB; }