From 00bd8a25fb1cc1d1c085d71a4e1f0a01aa1fadea Mon Sep 17 00:00:00 2001 From: Pavlo Yatsukhnenko Date: Fri, 3 May 2024 18:06:10 +0300 Subject: [PATCH] Fixed issue with Predis and replication connection (#520) --- CHANGELOG.md | 4 ++++ includes/object-cache.php | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85235a31..2da9d1a3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +- Fixed `wp_cache_flush_group` issue with Predis and replication connection + ## 2.5.2 - Respect `WP_REDIS_FLUSH_TIMEOUT` in Lua flush scripts diff --git a/includes/object-cache.php b/includes/object-cache.php index b28d6055..7639c0cf 100644 --- a/includes/object-cache.php +++ b/includes/object-cache.php @@ -1612,8 +1612,12 @@ protected function execute_lua_script( $script ) { $flushTimeout = defined( 'WP_REDIS_FLUSH_TIMEOUT' ) ? WP_REDIS_FLUSH_TIMEOUT : 5; if ( $this->is_predis() ) { - $timeout = $this->redis->getConnection()->getParameters()->read_write_timeout ?? ini_get( 'default_socket_timeout' ); - stream_set_timeout( $this->redis->getConnection()->getResource(), $flushTimeout ); + $connection = $this->redis->getConnection(); + if ($connection instanceof Predis\Connection\Replication\ReplicationInterface) { + $connection = $connection->getMaster(); + } + $timeout = $connection->getParameters()->read_write_timeout ?? ini_get( 'default_socket_timeout' ); + stream_set_timeout( $connection->getResource(), $flushTimeout ); } else { $timeout = $this->redis->getOption( Redis::OPT_READ_TIMEOUT ); $this->redis->setOption( Redis::OPT_READ_TIMEOUT, $flushTimeout ); @@ -1627,7 +1631,7 @@ protected function execute_lua_script( $script ) { } if ( $this->is_predis() ) { - stream_set_timeout( $this->redis->getConnection()->getResource(), $timeout ); + stream_set_timeout( $connection->getResource(), $timeout ); } else { $this->redis->setOption( Redis::OPT_READ_TIMEOUT, $timeout ); }