Skip to content

Commit

Permalink
Fix Predis cluster flush (#529)
Browse files Browse the repository at this point in the history
* Fix Predis cluster flush

* Update CHANGELOG.md

---------

Co-authored-by: Till Krüss <[email protected]>
  • Loading branch information
yatsukhnenko and tillkruss authored Jun 10, 2024
1 parent 781430a commit d4e4497
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Unreleased

- Fixed issues with Predis and replication connections
- Fixed several issues with Predis and cluster/replicated connection
- Fixed rare fatal error in `show_error_and_die()` (one more time)

## 2.5.2
Expand Down
17 changes: 8 additions & 9 deletions includes/class-predis.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,10 @@ public function connect( $read_timeout = null ) {
* @return bool
*/
public function flush( $throw_exception = false ) {
$flush_timeout = defined( 'WP_REDIS_FLUSH_TIMEOUT' )
? intval( WP_REDIS_FLUSH_TIMEOUT )
: 5;

if ( is_null( $this->redis ) ) {
$flush_timeout = defined( 'WP_REDIS_FLUSH_TIMEOUT' )
? intval( WP_REDIS_FLUSH_TIMEOUT )
: 5;
try {
$this->connect( $flush_timeout );
} catch ( Exception $exception ) {
Expand All @@ -153,16 +152,16 @@ public function flush( $throw_exception = false ) {

return false;
}
}

if ( is_null( $this->redis ) ) {
return false;
if ( is_null( $this->redis ) ) {
return false;
}
}

if ( defined( 'WP_REDIS_CLUSTER' ) ) {
try {
foreach ( $this->redis->_masters() as $master ) {
$this->redis->flushdb( $master );
foreach ( $this->redis->getIterator() as $master ) {
$master->flushdb();
}
} catch ( Exception $exception ) {
if ( $throw_exception ) {
Expand Down

0 comments on commit d4e4497

Please sign in to comment.