Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Predis cluster flush #529

Merged
merged 2 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading