Skip to content
Snippets Groups Projects
Commit 2da95e28 authored by Erick Hitter's avatar Erick Hitter
Browse files

Only set database value when not zero, otherwise unnecessary `SELECT` calls result

parent 76bbe263
Branches
No related tags found
No related merge requests found
......@@ -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;
......
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment