Skip to content

Commit

Permalink
Fixed issue with Predis and replication connection (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsukhnenko authored May 3, 2024
1 parent eae0725 commit 00bd8a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 7 additions & 3 deletions includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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 );
}
Expand Down

0 comments on commit 00bd8a2

Please sign in to comment.