Skip to content

Commit 00bd8a2

Browse files
authored
Fixed issue with Predis and replication connection (#520)
1 parent eae0725 commit 00bd8a2

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fixed `wp_cache_flush_group` issue with Predis and replication connection
6+
37
## 2.5.2
48

59
- Respect `WP_REDIS_FLUSH_TIMEOUT` in Lua flush scripts

includes/object-cache.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,12 @@ protected function execute_lua_script( $script ) {
16121612
$flushTimeout = defined( 'WP_REDIS_FLUSH_TIMEOUT' ) ? WP_REDIS_FLUSH_TIMEOUT : 5;
16131613

16141614
if ( $this->is_predis() ) {
1615-
$timeout = $this->redis->getConnection()->getParameters()->read_write_timeout ?? ini_get( 'default_socket_timeout' );
1616-
stream_set_timeout( $this->redis->getConnection()->getResource(), $flushTimeout );
1615+
$connection = $this->redis->getConnection();
1616+
if ($connection instanceof Predis\Connection\Replication\ReplicationInterface) {
1617+
$connection = $connection->getMaster();
1618+
}
1619+
$timeout = $connection->getParameters()->read_write_timeout ?? ini_get( 'default_socket_timeout' );
1620+
stream_set_timeout( $connection->getResource(), $flushTimeout );
16171621
} else {
16181622
$timeout = $this->redis->getOption( Redis::OPT_READ_TIMEOUT );
16191623
$this->redis->setOption( Redis::OPT_READ_TIMEOUT, $flushTimeout );
@@ -1627,7 +1631,7 @@ protected function execute_lua_script( $script ) {
16271631
}
16281632

16291633
if ( $this->is_predis() ) {
1630-
stream_set_timeout( $this->redis->getConnection()->getResource(), $timeout );
1634+
stream_set_timeout( $connection->getResource(), $timeout );
16311635
} else {
16321636
$this->redis->setOption( Redis::OPT_READ_TIMEOUT, $timeout );
16331637
}

0 commit comments

Comments
 (0)