From a9bead9fe85fc246467695b530ec6c8f9855143c 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 PHP when testing in CircleCI. --- .circleci/config.yml | 16 ++++++++++++++++ object-cache.php | 4 ++-- wp-redis.php | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 1cd5e74..1435c27 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -27,6 +27,10 @@ jobs: - restore_cache: keys: - test-lint-dependencies-{{ checksum "composer.json" }} + - run: + name: "Increate PHP memory limit" + command: | + echo 'memory_limit = -1' | sudo tee -a /usr/local/etc/php/conf.d/docker-php-memlimit.ini - run: composer install -n --prefer-dist - save_cache: key: test-lint-dependencies-{{ checksum "composer.json" }} @@ -46,6 +50,10 @@ jobs: - restore_cache: keys: - test-behat-dependencies-{{ checksum "composer.json" }} + - run: + name: "Increate PHP memory limit" + command: | + echo 'memory_limit = -1' | sudo tee -a /usr/local/etc/php/conf.d/docker-php-memlimit.ini - run: composer install -n --prefer-dist - save_cache: key: test-behat-dependencies-{{ checksum "composer.json" }} @@ -94,6 +102,10 @@ jobs: - restore_cache: keys: - test-phpunit-dependencies-{{ checksum "composer.json" }} + - run: + name: "Increate PHP memory limit" + command: | + echo 'memory_limit = -1' | sudo tee -a /usr/local/etc/php/conf.d/docker-php-memlimit.ini - run: composer install -n --prefer-dist - save_cache: key: test-phpunit-dependencies-{{ checksum "composer.json" }} @@ -133,6 +145,10 @@ jobs: - restore_cache: keys: - test-phpunit-dependencies-{{ checksum "composer.json" }} + - run: + name: "Increate PHP memory limit" + command: | + echo 'memory_limit = -1' | sudo tee -a /usr/local/etc/php/conf.d/docker-php-memlimit.ini - run: composer install -n --prefer-dist - save_cache: key: test-phpunit-dependencies-{{ checksum "composer.json" }} diff --git a/object-cache.php b/object-cache.php index 4f04b77..c20156f 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..07af5e1 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 {