From e721a6a714d1c8ad085ed0f3efa1ca919b132f05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Sat, 5 Nov 2022 16:26:06 -0700 Subject: [PATCH 01/16] remove old rules --- phpstan-baseline.neon | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 77fd0c0b..169c11ba 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Parameter \\#1 \\$name of class RedisCluster constructor expects string\\|null, array given\\.$#" - count: 1 - path: .php-tools/object-cache.php - - - - message: "#^Call to function is_string\\(\\) with array\\{'tcp\\://127\\.0\\.0\\.1…', 'tcp\\://127\\.0\\.0\\.2…', 'tcp\\://127\\.0\\.0\\.3…'\\} will always evaluate to false\\.$#" - count: 3 - path: .php-tools/object-cache.php - - message: "#^Class RedisCluster constructor invoked with 1 parameter, 2\\-6 required\\.$#" count: 1 From ee806a495b770f591ee760d16fd4ec77bd16ae69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Sat, 5 Nov 2022 16:32:00 -0700 Subject: [PATCH 02/16] bump dev version --- includes/object-cache.php | 2 +- redis-cache.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/object-cache.php b/includes/object-cache.php index da186a0c..02843861 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -3,7 +3,7 @@ * Plugin Name: Redis Object Cache Drop-In * Plugin URI: https://wordpress.org/plugins/redis-cache/ * Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI. - * Version: 2.2.2 + * Version: 2.2.3-dev * Author: Till Krüss * Author URI: https://objectcache.pro * License: GPLv3 diff --git a/redis-cache.php b/redis-cache.php index 2e94d240..c6cf3085 100644 --- a/redis-cache.php +++ b/redis-cache.php @@ -3,7 +3,7 @@ * Plugin Name: Redis Object Cache * Plugin URI: https://wordpress.org/plugins/redis-cache/ * Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI. - * Version: 2.2.2 + * Version: 2.2.3-dev * Text Domain: redis-cache * Domain Path: /languages * Network: true From dfd3356f813157085c3422becbb08d5a739c2910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Wed, 9 Nov 2022 10:21:25 -0800 Subject: [PATCH 03/16] update Credis to v1.14.0 --- CHANGELOG.md | 4 ++++ dependencies/colinmollenhour/credis/Client.php | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f28efe..d4896ed1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Updated Credis to v1.14.0 + ## 2.2.2 - Use `QM_Data_Cache` instead of `QM_Data` diff --git a/dependencies/colinmollenhour/credis/Client.php b/dependencies/colinmollenhour/credis/Client.php index 97c18f1b..4689a1bb 100755 --- a/dependencies/colinmollenhour/credis/Client.php +++ b/dependencies/colinmollenhour/credis/Client.php @@ -1587,7 +1587,7 @@ protected function decode_reply($name, $response, array &$arguments = array() ) */ private static function _prepare_command($args) { - return sprintf('*%d%s%s%s', count($args), CRLF, implode(CRLF, array_map(array('self', '_map'), $args)), CRLF); + return sprintf('*%d%s%s%s', count($args), CRLF, implode(CRLF, array_map([static::class, '_map'], $args)), CRLF); } private static function _map($arg) From b0f8586ddc6a05d5b987e022c700241503e748c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Thu, 10 Nov 2022 09:14:57 -0800 Subject: [PATCH 04/16] drop delay bs --- CHANGELOG.md | 1 + includes/object-cache.php | 21 ++++++--------------- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4896ed1..e02af30c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - Updated Credis to v1.14.0 +- Drop `$delay` parameter from `wp_cache_flush()` ## 2.2.2 diff --git a/includes/object-cache.php b/includes/object-cache.php index 02843861..00f49d62 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -141,14 +141,12 @@ function wp_cache_delete_multiple( array $keys, $group = '' ) { * Invalidate all items in the cache. If `WP_REDIS_SELECTIVE_FLUSH` is `true`, * only keys prefixed with the `WP_REDIS_PREFIX` are flushed. * - * @param int $delay Number of seconds to wait before invalidating the items. - * * @return bool Returns TRUE on success or FALSE on failure. */ -function wp_cache_flush( $delay = 0 ) { +function wp_cache_flush() { global $wp_object_cache; - return $wp_object_cache->flush( $delay ); + return $wp_object_cache->flush(); } /** @@ -1533,16 +1531,9 @@ public function flush_runtime() { * Invalidate all items in the cache. If `WP_REDIS_SELECTIVE_FLUSH` is `true`, * only keys prefixed with the `WP_REDIS_PREFIX` are flushed. * - * @param int $delay Number of seconds to wait before invalidating the items. - * @return bool Returns TRUE on success or FALSE on failure. + * @return bool True on success, false on failure. */ - public function flush( $delay = 0 ) { - $delay = abs( (int) $delay ); - - if ( $delay ) { - sleep( $delay ); - } - + public function flush() { $results = []; $this->cache = []; @@ -1607,12 +1598,12 @@ public function flush( $delay = 0 ) { * * @since 1.3.5 * @param null|array $results Array of flush results. - * @param int $delay Given number of seconds to waited before invalidating the items. + * @param int $deprecated Unused. Default 0. * @param bool $seletive Whether a selective flush took place. * @param string $salt The defined key prefix. * @param float $execute_time Execution time for the request in seconds. */ - do_action( 'redis_object_cache_flush', $results, $delay, $selective, $salt, $execute_time ); + do_action( 'redis_object_cache_flush', $results, 0, $selective, $salt, $execute_time ); } } From f08943664ba97026b76e3767786f80a89b89d203 Mon Sep 17 00:00:00 2001 From: Wilbur Powery Date: Fri, 11 Nov 2022 11:02:13 -0600 Subject: [PATCH 05/16] Add wp_cache_flush_group implementation (#399) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add wp_cache_flush_group implementation * Rename method * Finish method implementation * silence * formatting * Remove weird file * Change to foreach for performance * Update docblocks to please phpstan * Remove ignoreError phpstan config since error doesn't seem to be happening anymore? * update plugin version in readme so tests can pass * wrong version, of course * formatting Co-authored-by: Till Krüss --- includes/class-qm-output.php | 4 +- includes/object-cache.php | 97 ++++++++++++++++++++++++++++++++++-- phpstan.neon.dist | 4 -- readme.txt | 2 +- 4 files changed, 96 insertions(+), 11 deletions(-) diff --git a/includes/class-qm-output.php b/includes/class-qm-output.php index 87acd823..a6e40b71 100644 --- a/includes/class-qm-output.php +++ b/includes/class-qm-output.php @@ -24,8 +24,8 @@ class QM_Output extends QM_Output_Html { public function __construct( QM_Collector $collector ) { parent::__construct( $collector ); - add_filter( 'qm/output/menus', [ $this, 'admin_menu' ], 30 ); - add_filter( 'qm/output/panel_menus', [ $this, 'panel_menu' ] ); + add_filter( 'qm/output/menus', [ $this, 'admin_menu' ], 30 ); // @phpstan-ignore-line + add_filter( 'qm/output/panel_menus', [ $this, 'panel_menu' ] ); // @phpstan-ignore-line } /** diff --git a/includes/object-cache.php b/includes/object-cache.php index 00f49d62..87826c7a 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -35,9 +35,9 @@ function wp_cache_supports( $feature ) { case 'get_multiple': case 'delete_multiple': case 'flush_runtime': + case 'flush_group': return true; - case 'flush_group': default: return false; } @@ -149,6 +149,19 @@ function wp_cache_flush() { return $wp_object_cache->flush(); } +/** + * Removes all cache items in a group. + * + * @param string $group Name of group to remove from cache. + * @return true Returns TRUE on success or FALSE on failure. + */ +function wp_cache_flush_group( $group ) +{ + global $wp_object_cache; + + return $wp_object_cache->flush_group( $group ); +} + /** * Removes all cache items from the in-memory runtime cache. * @@ -395,7 +408,7 @@ class WP_Object_Cache { /** * List of global groups. * - * @var array + * @var array */ public $global_groups = [ 'blog-details', @@ -1620,6 +1633,81 @@ public function flush() { return true; } + /** + * Removes all cache items in a group. + * + * @param string $group Name of group to remove from cache. + * @return bool Returns TRUE on success or FALSE on failure. + */ + public function flush_group( $group ) + { + $san_group = $this->sanitize_key_part( $group ); + + if ( is_multisite() && ! $this->is_global_group( $san_group ) ) { + $salt = str_replace( "{$this->blog_prefix}:", '*:', $this->fast_build_key( '*', $san_group ) ); + } else { + $salt = $this->fast_build_key( '*', $san_group ); + } + + foreach ( $this->cache as $key => $value ) { + if ( strpos( $key, "{$san_group}:" ) === 0 || strpos( $key, ":{$san_group}:" ) !== false ) { + unset( $this->cache[ $key ] ); + } + } + + if ( in_array( $san_group, $this->unflushable_groups ) ) { + return false; + } + + if ( ! $this->redis_status() ) { + return false; + } + + $results = []; + + $start_time = microtime( true ); + $script = $this->lua_flush_closure( $salt, false ); + + try { + if ( defined( 'WP_REDIS_CLUSTER' ) ) { + foreach ( $this->redis->_masters() as $master ) { + $redis = new Redis; + $redis->connect( $master[0], $master[1] ); + $results[] = $this->parse_redis_response( $script() ); + unset( $redis ); + } + } else { + $results[] = $this->parse_redis_response( $script() ); + } + } catch ( Exception $exception ) { + $this->handle_exception( $exception ); + + return false; + } + + if ( function_exists( 'do_action' ) ) { + $execute_time = microtime( true ) - $start_time; + + /** + * Fires on every group cache flush + * + * @param null|array $results Array of flush results. + * @param string $salt The defined key prefix. + * @param float $execute_time Execution time for the request in seconds. + * @since 2.2.3 + */ + do_action( 'redis_object_cache_flush_group', $results, $salt, $execute_time ); + } + + foreach ( $results as $result ) { + if ( ! $result ) { + return false; + } + } + + return true; + } + /** * Returns a closure to flush selectively. * @@ -1659,10 +1747,11 @@ function ( $character ) { * Returns a closure ready to be called to flush selectively ignoring unflushable groups. * * @param string $salt The salt to be used to differentiate. + * @param bool $escape ... * @return callable Generated callable executing the lua script. */ - protected function lua_flush_closure( $salt ) { - $salt = $this->glob_quote( $salt ); + protected function lua_flush_closure( $salt, $escape = true ) { + $salt = $escape ? $this->glob_quote( $salt ) : $salt; return function () use ( $salt ) { $script = << Date: Fri, 11 Nov 2022 09:02:57 -0800 Subject: [PATCH 06/16] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e02af30c..76204098 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Added `wp_cache_flush_group()` support - Updated Credis to v1.14.0 - Drop `$delay` parameter from `wp_cache_flush()` From 0a33669ff2b8a5c680f9c48ee617bce2adfd6c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 2 Dec 2022 10:27:42 -0800 Subject: [PATCH 07/16] fix rare `TypeError` Error message: Uncaught TypeError: array_values(): Argument #1 ($array) must be of type array, null given --- includes/diagnostics.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/includes/diagnostics.php b/includes/diagnostics.php index 68a0eabb..375d3274 100644 --- a/includes/diagnostics.php +++ b/includes/diagnostics.php @@ -32,11 +32,9 @@ } catch ( Exception $exception ) { $info[ 'Connection Exception' ] = sprintf( '%s (%s)', $exception->getMessage(), get_class( $exception ) ); } - - $info[ 'Errors' ] = wp_json_encode( - array_values( $wp_object_cache->errors ), - JSON_PRETTY_PRINT - ); + + $errors = is_array( $wp_object_cache->errors ) ? $wp_object_cache->errors : []; + $info[ 'Errors' ] = wp_json_encode( array_values( $errors ), JSON_PRETTY_PRINT ); } $info['PhpRedis'] = class_exists( 'Redis' ) ? phpversion( 'redis' ) : 'Not loaded'; From 19d45eca5c89174600f75f071e4169f25a0698d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Tue, 13 Dec 2022 09:23:01 -0800 Subject: [PATCH 08/16] mark as tested with 6.1; switch to https --- readme.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/readme.txt b/readme.txt index de400d4d..b2b09f34 100644 --- a/readme.txt +++ b/readme.txt @@ -3,18 +3,18 @@ Contributors: tillkruess Donate link: https://github.com/sponsors/tillkruss Tags: redis, object cache, cache, object caching, caching performance, relay, predis, phpredis Requires at least: 3.3 -Tested up to: 6.0 +Tested up to: 6.1 Requires PHP: 7.2 Stable tag: 2.2.3-dev License: GPLv3 -License URI: http://www.gnu.org/licenses/gpl-3.0.html +License URI: https://www.gnu.org/licenses/gpl-3.0.html A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI. == Description == -A persistent object cache backend powered by Redis. Supports [Predis](https://github.com/predis/predis/), [PhpRedis (PECL)](https://github.com/phpredis/phpredis), [Relay](https://relaycache.com), replication, sentinels, clustering and [WP-CLI](http://wp-cli.org/). +A persistent object cache backend powered by Redis. Supports [Predis](https://github.com/predis/predis/), [PhpRedis (PECL)](https://github.com/phpredis/phpredis), [Relay](https://relaycache.com), replication, sentinels, clustering and [WP-CLI](https://wp-cli.org/). To adjust the connection parameters, prefix cache keys or configure replication/clustering, please see [our wiki](https://github.com/rhubarbgroup/redis-cache/wiki). @@ -37,12 +37,12 @@ Learn more about [Object Cache Pro](https://objectcache.pro/?ref=oss&utm_sou == Installation == -For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](http://codex.wordpress.org/Managing_Plugins#Installing_Plugins). +For detailed installation instructions, please read the [standard installation procedure for WordPress plugins](https://codex.wordpress.org/Managing_Plugins#Installing_Plugins). -1. Make sure [Redis is installed and running](http://redis.io/topics/quickstart). +1. Make sure [Redis is installed and running](https://redis.io/topics/quickstart). 2. Install and activate plugin. 3. Enable the object cache under _Settings -> Redis_, or in Multisite setups under _Network Admin -> Settings -> Redis_. -4. If necessary, adjust [connection parameters](http://wordpress.org/extend/plugins/redis-cache/other_notes/). +4. If necessary, adjust [connection parameters](https://wordpress.org/extend/plugins/redis-cache/other_notes/). If your server doesn't support the [WordPress Filesystem API](https://codex.wordpress.org/Filesystem_API), you have to manually copy the `object-cache.php` file from the `/plugins/redis-cache/includes/` directory to the `/wp-content/` directory. From 4b3d6ff14d335c16d40762f2c55382600c57309b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Tue, 20 Dec 2022 19:59:37 -0800 Subject: [PATCH 09/16] use new r2 link --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 42c523ac..dfc1a719 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "scripts": { "stan": [ "@php -r \"is_dir('.php-tools') || mkdir('.php-tools');\"", - "@php -r \"file_exists('.php-tools/relay.stub.php') || system('curl https://cachewerk.s3.amazonaws.com/relay/dev/relay.stub.php -o ./.php-tools/relay.stub.php');\"", + "@php -r \"file_exists('.php-tools/relay.stub.php') || system('curl https://builds.r2.relay.so/dev/relay.stub.php -o ./.php-tools/relay.stub.php');\"", "sed -e 's#WP_Object_Cache#Redis_Pro_WP_Object_Cache#;s#class Redis_Pro_WP_Object_Cache#& extends WP_Object_Cache#' includes/object-cache.php > .php-tools/object-cache.php", "phpstan analyze" ] From a20c7a0b419d4bcc4ccc1bb623852158039d13f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Fri, 23 Dec 2022 11:11:47 -0800 Subject: [PATCH 10/16] add `WP_REDIS_PLUGIN_PATH` to diagnostics --- includes/diagnostics.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/diagnostics.php b/includes/diagnostics.php index 375d3274..0d40bb9e 100644 --- a/includes/diagnostics.php +++ b/includes/diagnostics.php @@ -85,6 +85,7 @@ 'WP_REDIS_MAXTTL', 'WP_REDIS_PREFIX', 'WP_CACHE_KEY_SALT', + 'WP_REDIS_PLUGIN_PATH', 'WP_REDIS_GLOBAL_GROUPS', 'WP_REDIS_IGNORED_GROUPS', 'WP_REDIS_UNFLUSHABLE_GROUPS', From c5b438b080bf3f316329b42957776cec24ac0963 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 9 Jan 2023 04:20:59 +0000 Subject: [PATCH 11/16] Fix CS (#407) --- includes/diagnostics.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/diagnostics.php b/includes/diagnostics.php index 0d40bb9e..62a93ed4 100644 --- a/includes/diagnostics.php +++ b/includes/diagnostics.php @@ -32,7 +32,7 @@ } catch ( Exception $exception ) { $info[ 'Connection Exception' ] = sprintf( '%s (%s)', $exception->getMessage(), get_class( $exception ) ); } - + $errors = is_array( $wp_object_cache->errors ) ? $wp_object_cache->errors : []; $info[ 'Errors' ] = wp_json_encode( array_values( $errors ), JSON_PRETTY_PRINT ); } From a601b7345b810e8f2e4f5abc5579727144651037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Mon, 9 Jan 2023 16:54:22 +0000 Subject: [PATCH 12/16] Fix grokzen/redis-cluster Docker image (#406) v5 was dropped --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 22792fce..b13700a3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -111,7 +111,7 @@ jobs: fail-fast: false matrix: php: ['7.2', '7.3', '7.4', '8.0', '8.1'] - redis: ['5.0.12', '6.2.1'] + redis: ['6.2.8', '7.0.7'] steps: - name: Checkout From 2a8871e1486414af665a03cd32f84b42e165522f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Viktor=20Sz=C3=A9pe?= Date: Tue, 10 Jan 2023 23:43:07 +0000 Subject: [PATCH 13/16] Improve static analysis (#408) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Relay stubs contain PHP 8.2 code * Improve static analysis * Fix Relay version in CI * Disable xdebug for PHPStan in CI * Run CI on Relay 0.4.6 too * formatting * drop 8.0 checks * drop old relay version * sort [skip ci] Co-authored-by: Till Krüss --- .github/workflows/lint.yml | 17 +++++++++++-- .gitignore | 2 +- composer.json | 12 ++++----- includes/class-plugin.php | 1 + includes/class-qm-output.php | 4 +-- includes/diagnostics.php | 5 ++-- phpstan-baseline.neon | 35 +++++++++++---------------- phpstan.neon.dist | 7 +++--- tests/PHPStan/query-monitor-stubs.php | 4 ++- 9 files changed, 47 insertions(+), 40 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4fff6952..04622bc1 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,13 +5,14 @@ on: [push, pull_request] jobs: phpstan: - name: PHPStan (PHP ${{ matrix.php }}) + name: PHPStan (PHP ${{ matrix.php }}; Relay ${{ matrix.relay }}) runs-on: ubuntu-latest strategy: fail-fast: false matrix: - php: ['7.4', '8.0'] + php: ['7.4', '8.2'] + relay: ['0.5.1'] steps: - name: Checkout @@ -22,6 +23,18 @@ jobs: with: php-version: ${{ matrix.php }} extensions: msgpack, igbinary, mbstring, redis-5.3.7 + coverage: none + + - name: Install Relay PHP extension + run: | + curl -L "https://builds.r2.relay.so/v${{ matrix.relay }}/relay-v${{ matrix.relay }}-php${{ matrix.php }}-debian-x86-64.tar.gz" | tar xz + cd relay-v${{ matrix.relay }}-php${{ matrix.php }}-debian-x86-64/ + sudo cp -v relay.ini $(php-config --ini-dir) + sudo cp -v relay-pkg.so $(php-config --extension-dir)/relay.so + sudo sed -i -e "s/00000000-0000-0000-0000-000000000000/$(cat /proc/sys/kernel/random/uuid)/" $(php-config --extension-dir)/relay.so + + - name: Show Relay configuration + run: php --ri relay - name: Install PHP Dependencies uses: ramsey/composer-install@v2 diff --git a/.gitignore b/.gitignore index df22fe02..c53c71ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ /.wp-test /.phpunit.cache -/.php-tools /vendor /reports +/tests/PHPStan/object-cache.php .phpunit.result.cache composer.lock config.sh diff --git a/composer.json b/composer.json index dfc1a719..07dfd3ae 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "yoast/wp-test-utils": "^1.0", "dms/phpunit-arraysubset-asserts": "^0.4.0", "szepeviktor/phpstan-wordpress": "^1.1", - "php-stubs/wp-cli-stubs": "^2.6" + "php-stubs/wp-cli-stubs": "^2.7" }, "autoload-dev": { "psr-4": { @@ -53,17 +53,15 @@ }, "scripts": { "stan": [ - "@php -r \"is_dir('.php-tools') || mkdir('.php-tools');\"", - "@php -r \"file_exists('.php-tools/relay.stub.php') || system('curl https://builds.r2.relay.so/dev/relay.stub.php -o ./.php-tools/relay.stub.php');\"", - "sed -e 's#WP_Object_Cache#Redis_Pro_WP_Object_Cache#;s#class Redis_Pro_WP_Object_Cache#& extends WP_Object_Cache#' includes/object-cache.php > .php-tools/object-cache.php", + "sed -e 's#WP_Object_Cache#Redis_Pro_WP_Object_Cache#;s#class Redis_Pro_WP_Object_Cache#& extends WP_Object_Cache#' includes/object-cache.php > tests/PHPStan/object-cache.php", "phpstan analyze" ] }, "config": { "allow-plugins": { - "composer/installers": true, - "mnsami/composer-custom-directory-installer": true, - "dealerdirect/phpcodesniffer-composer-installer": true + "composer/installers": true, + "mnsami/composer-custom-directory-installer": true, + "dealerdirect/phpcodesniffer-composer-installer": true } } } diff --git a/includes/class-plugin.php b/includes/class-plugin.php index 29b7aac3..8d6795c3 100644 --- a/includes/class-plugin.php +++ b/includes/class-plugin.php @@ -997,6 +997,7 @@ public function initialize_filesystem( $url, $silent = false ) { * @return true|WP_Error */ public function test_filesystem_writing() { + /** @var \WP_Filesystem_Base $wp_filesystem */ global $wp_filesystem; if ( ! $this->initialize_filesystem( '', true ) ) { diff --git a/includes/class-qm-output.php b/includes/class-qm-output.php index a6e40b71..87acd823 100644 --- a/includes/class-qm-output.php +++ b/includes/class-qm-output.php @@ -24,8 +24,8 @@ class QM_Output extends QM_Output_Html { public function __construct( QM_Collector $collector ) { parent::__construct( $collector ); - add_filter( 'qm/output/menus', [ $this, 'admin_menu' ], 30 ); // @phpstan-ignore-line - add_filter( 'qm/output/panel_menus', [ $this, 'panel_menu' ] ); // @phpstan-ignore-line + add_filter( 'qm/output/menus', [ $this, 'admin_menu' ], 30 ); + add_filter( 'qm/output/panel_menus', [ $this, 'panel_menu' ] ); } /** diff --git a/includes/diagnostics.php b/includes/diagnostics.php index 62a93ed4..a5fadd77 100644 --- a/includes/diagnostics.php +++ b/includes/diagnostics.php @@ -102,15 +102,16 @@ } if ( defined( 'WP_REDIS_PASSWORD' ) ) { + /** @var string|array|null $password */ $password = WP_REDIS_PASSWORD; if ( is_array( $password ) ) { - if ( isset( $password[1] ) && ! is_null( $password[1] ) && '' !== $password[1] ) { + if ( isset( $password[1] ) && '' !== $password[1] ) { $password[1] = str_repeat( '•', 8 ); } $info['WP_REDIS_PASSWORD'] = wp_json_encode( $password, JSON_UNESCAPED_UNICODE ); - } elseif ( ! is_null( $password ) && '' !== $password ) { + } elseif ( is_string( $password ) && '' !== $password ) { $info['WP_REDIS_PASSWORD'] = str_repeat( '•', 8 ); } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 169c11ba..138f7868 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,56 +1,49 @@ parameters: ignoreErrors: + # https://github.com/phpredis/phpredis/blob/b193a6d051969a4d5bec33c958e9033f0d983110/redis_cluster.stub.php#L50 - message: "#^Class RedisCluster constructor invoked with 1 parameter, 2\\-6 required\\.$#" count: 1 - path: .php-tools/object-cache.php + path: tests/PHPStan/object-cache.php + # PHPStan shortcoming - message: "#^Parameter \\#1 \\$autoload_function of function spl_autoload_register expects callable\\(string\\)\\: void, array\\{\\$this\\(Rhubarb\\\\RedisCache\\\\Autoloader\\), 'load_class'\\} given\\.$#" count: 1 path: includes/class-autoloader.php + # Redis Cache's `cache` property differs from core - message: "#^Access to private property WP_Object_Cache\\:\\:\\$cache\\.$#" count: 2 path: includes/class-plugin.php - - - message: "#^Call to function is_array\\(\\) with string will always evaluate to false\\.$#" - count: 1 - path: includes/diagnostics.php - - - - message: "#^Call to function is_null\\(\\) with string will always evaluate to false\\.$#" - count: 1 - path: includes/diagnostics.php - + # Redis Cache implementation differs from core - message: "#^Class WP_Object_Cache constructor invoked with 1 parameter, 0 required\\.$#" count: 1 path: includes/diagnostics.php - - - message: "#^Offset 1 on \\*NEVER\\* in isset\\(\\) always exists and is always null\\.$#" - count: 1 - path: includes/diagnostics.php - - - - message: "#^Result of && is always false\\.$#" - count: 2 - path: includes/diagnostics.php - + # Included template calling protected method - message: "#^Call to protected method after_non_tabular_output\\(\\) of class QM_Output_Html\\.$#" count: 1 path: includes/ui/query-monitor.php + # Included template calling protected method - message: "#^Call to protected method before_non_tabular_output\\(\\) of class QM_Output_Html\\.$#" count: 1 path: includes/ui/query-monitor.php + # Included template using private property - message: "#^Access to private property Rhubarb\\\\RedisCache\\\\Plugin\\:\\:\\$page\\.$#" count: 1 path: includes/ui/widget.php + + # WP_FilesystemBase::delete() is an impure function + - + message: "#^Negated boolean expression is always false\\.$#" + count: 1 + path: includes/class-plugin.php diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 0139cc67..f58c5603 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,3 +1,5 @@ +# Running PHPStan needs ext-relay. + includes: - vendor/szepeviktor/phpstan-wordpress/extension.neon - phpstan-baseline.neon @@ -21,12 +23,9 @@ parameters: - tests/PHPStan/query-monitor-stubs.php - vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php - scanFiles: - - .php-tools/relay.stub.php - paths: - includes/ - - .php-tools/object-cache.php + - tests/PHPStan/object-cache.php excludePaths: - includes/object-cache.php diff --git a/tests/PHPStan/query-monitor-stubs.php b/tests/PHPStan/query-monitor-stubs.php index 5fb7b701..bd9b84fd 100644 --- a/tests/PHPStan/query-monitor-stubs.php +++ b/tests/PHPStan/query-monitor-stubs.php @@ -51,6 +51,7 @@ public function Debug_Bar_Panel($title = '') class QM_Dispatchers implements \IteratorAggregate { private $items = array(); + #[\ReturnTypeWillChange] public function getIterator() { } @@ -299,7 +300,7 @@ public final function plugin_base() /** * Populates and returns the current plugin info. */ - private final function _plugin($item, $file = '') + private function _plugin($item, $file = '') { } public static function php_version_met() @@ -401,6 +402,7 @@ class QM_Collectors implements \IteratorAggregate { private $items = array(); private $processed = \false; + #[\ReturnTypeWillChange] public function getIterator() { } From 7a7e35cbde5cf94874a0381e9879ac7efb81f9b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kr=C3=BCss?= Date: Tue, 10 Jan 2023 15:57:42 -0800 Subject: [PATCH 14/16] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76204098..fb8e1ab4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Added `wp_cache_flush_group()` support - Updated Credis to v1.14.0 - Drop `$delay` parameter from `wp_cache_flush()` +- Prevent rare error in diagnostics when reading connection errors ## 2.2.2 From f9654e972a7768ab2be2acbdc7e92e93541fe0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Tue, 10 Jan 2023 16:00:20 -0800 Subject: [PATCH 15/16] update pot --- languages/redis-cache.pot | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/languages/redis-cache.pot b/languages/redis-cache.pot index 6bd71393..53034f63 100644 --- a/languages/redis-cache.pot +++ b/languages/redis-cache.pot @@ -1,17 +1,17 @@ -# Copyright (C) 2022 Till Krüss +# Copyright (C) 2023 Till Krüss # This file is distributed under the GPLv3. msgid "" msgstr "" -"Project-Id-Version: Redis Object Cache 2.2.2\n" +"Project-Id-Version: Redis Object Cache 2.2.3\n" "Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/redis-cache\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2022-11-05T23:18:33+00:00\n" +"POT-Creation-Date: 2023-01-11T00:00:10+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"X-Generator: WP-CLI 2.6.0\n" +"X-Generator: WP-CLI 2.7.1\n" "X-Domain: redis-cache\n" #. Plugin Name of the plugin @@ -193,35 +193,35 @@ msgstr "" msgid "Retrieved %1$d objects (%2$s) from Redis using %3$s." msgstr "" -#: includes/class-plugin.php:1003 +#: includes/class-plugin.php:1004 msgid "Could not initialize filesystem." msgstr "" -#: includes/class-plugin.php:1010 +#: includes/class-plugin.php:1011 msgid "Object cache file doesn’t exist." msgstr "" -#: includes/class-plugin.php:1015 +#: includes/class-plugin.php:1016 msgid "Test file exists, but couldn’t be deleted." msgstr "" -#: includes/class-plugin.php:1020 +#: includes/class-plugin.php:1021 msgid "Content directory is not writable." msgstr "" -#: includes/class-plugin.php:1024 +#: includes/class-plugin.php:1025 msgid "Failed to copy test file." msgstr "" -#: includes/class-plugin.php:1028 +#: includes/class-plugin.php:1029 msgid "Copied test file doesn’t exist." msgstr "" -#: includes/class-plugin.php:1034 +#: includes/class-plugin.php:1035 msgid "Couldn’t verify test file contents." msgstr "" -#: includes/class-plugin.php:1038 +#: includes/class-plugin.php:1039 msgid "Copied test file couldn’t be deleted." msgstr "" From 29bc6dd27036f7ef5acab3374e3e4c0aab30da1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Till=20Kru=CC=88ss?= Date: Tue, 10 Jan 2023 16:00:31 -0800 Subject: [PATCH 16/16] bump version --- CHANGELOG.md | 2 +- includes/object-cache.php | 2 +- readme.txt | 9 ++++++++- redis-cache.php | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fb8e1ab4..9e854f71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 2.2.3 - Added `wp_cache_flush_group()` support - Updated Credis to v1.14.0 diff --git a/includes/object-cache.php b/includes/object-cache.php index 87826c7a..a41381a1 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -3,7 +3,7 @@ * Plugin Name: Redis Object Cache Drop-In * Plugin URI: https://wordpress.org/plugins/redis-cache/ * Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI. - * Version: 2.2.3-dev + * Version: 2.2.3 * Author: Till Krüss * Author URI: https://objectcache.pro * License: GPLv3 diff --git a/readme.txt b/readme.txt index b2b09f34..6c6f7abf 100644 --- a/readme.txt +++ b/readme.txt @@ -5,7 +5,7 @@ Tags: redis, object cache, cache, object caching, caching performance, relay, pr Requires at least: 3.3 Tested up to: 6.1 Requires PHP: 7.2 -Stable tag: 2.2.3-dev +Stable tag: 2.2.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html @@ -83,6 +83,13 @@ To see a list of all available WP-CLI commands, please see the [WP CLI commands == Changelog == += 2.2.3 = + +- Added `wp_cache_flush_group()` support +- Updated Credis to v1.14.0 +- Drop `$delay` parameter from `wp_cache_flush()` +- Prevent rare error in diagnostics when reading connection errors + = 2.2.2 = - Use `QM_Data_Cache` instead of `QM_Data` diff --git a/redis-cache.php b/redis-cache.php index c6cf3085..080da010 100644 --- a/redis-cache.php +++ b/redis-cache.php @@ -3,7 +3,7 @@ * Plugin Name: Redis Object Cache * Plugin URI: https://wordpress.org/plugins/redis-cache/ * Description: A persistent object cache backend powered by Redis. Supports Predis, PhpRedis, Relay, replication, sentinels, clustering and WP-CLI. - * Version: 2.2.3-dev + * Version: 2.2.3 * Text Domain: redis-cache * Domain Path: /languages * Network: true