From 5eccb44b900ba319a60f39a062d97d2a60b7cf2a Mon Sep 17 00:00:00 2001 From: Tim Nolte Date: Fri, 24 Jun 2022 15:35:16 -0400 Subject: [PATCH] Fixes assumption that CACHE_PORT & CACHE_PASSWORD are Set. * Falls back on port 6379 if the CACHE_PORT is not configured. * Doesn't require a CACHE_PASSWORD to be set when it isn't used, or can't be. * Increase memory limit for PHPUnit when testing in CircleCI. --- .circleci/config.yml | 16 ++++++++-------- object-cache.php | 4 ++-- wp-redis.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1cd5e74..8ef60b8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -113,12 +113,12 @@ jobs: name: "Run Tests" command: | bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest - composer phpunit - WP_MULTISITE=1 composer phpunit - WP_REDIS_USE_CACHE_GROUPS=1 composer phpunit + composer phpunit -d memory_limit=4G + WP_MULTISITE=1 composer phpunit -d memory_limit=4G + WP_REDIS_USE_CACHE_GROUPS=1 composer phpunit -d memory_limit=4G rm -rf $WP_TESTS_DIR $WP_CORE_DIR bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true - composer phpunit + composer phpunit -d memory_limit=4G test-phpunit-redis-enabled: working_directory: ~/pantheon-systems/wp-redis docker: @@ -154,9 +154,9 @@ jobs: name: "Run Tests" command: | bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 latest - composer phpunit - WP_MULTISITE=1 composer phpunit - WP_REDIS_USE_CACHE_GROUPS=1 composer phpunit + composer phpunit -d memory_limit=4G + WP_MULTISITE=1 composer phpunit -d memory_limit=4G + WP_REDIS_USE_CACHE_GROUPS=1 composer phpunit -d memory_limit=4G rm -rf $WP_TESTS_DIR $WP_CORE_DIR bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1 nightly true - composer phpunit + composer phpunit -d memory_limit=4G diff --git a/object-cache.php b/object-cache.php index 4f04b77..7d2ff63 100644 --- a/object-cache.php +++ b/object-cache.php @@ -1167,8 +1167,8 @@ public function build_client_parameters( $redis_server ) { if ( isset( $_SERVER['CACHE_HOST'] ) ) { $redis_server = array( 'host' => $_SERVER['CACHE_HOST'], - 'port' => $_SERVER['CACHE_PORT'], - 'auth' => $_SERVER['CACHE_PASSWORD'], + 'port' => ! empty( $_SERVER['CACHE_PORT'] ) ? $_SERVER['CACHE_PORT'] : 6379, + 'auth' => ! empty( $_SERVER['CACHE_PASSWORD'] ) ? $_SERVER['CACHE_PASSWORD'] : null, 'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0, ); } else { diff --git a/wp-redis.php b/wp-redis.php index 5da9639..c77f8f9 100644 --- a/wp-redis.php +++ b/wp-redis.php @@ -39,8 +39,8 @@ function wp_redis_get_info() { if ( isset( $_SERVER['CACHE_HOST'] ) ) { $redis_server = array( 'host' => $_SERVER['CACHE_HOST'], - 'port' => $_SERVER['CACHE_PORT'], - 'auth' => $_SERVER['CACHE_PASSWORD'], + 'port' => ! empty( $_SERVER['CACHE_PORT'] ) ? $_SERVER['CACHE_PORT'] : 6379, + 'auth' => ! empty( $_SERVER['CACHE_PASSWORD'] ) ? $_SERVER['CACHE_PASSWORD'] : null, 'database' => isset( $_SERVER['CACHE_DB'] ) ? $_SERVER['CACHE_DB'] : 0, ); } else {