Skip to content

Commit

Permalink
Handle unexpected result from Redis pipeline quietly. (#486)
Browse files Browse the repository at this point in the history
* Handle unexpected result from Redis pipeline quietly.

* Match return value after getting unexpected result to be as expected.
  • Loading branch information
martinkrcho authored Jul 21, 2023
1 parent 68fdd2a commit 018c6d8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,8 @@ protected function add_multiple_at_once( array $data, $group = 'default', $expir
}, $tx->{$method}() ?: [] );

if ( count( $results ) !== count( $keys ) ) {
throw new Exception( 'Redis pipeline returned unexpected result' );
$tx->discard();
return array_fill_keys( $keys, false );
}

$results = array_combine( $keys, $results );
Expand Down Expand Up @@ -1548,7 +1549,8 @@ protected function delete_multiple_at_once( array $keys, $group = 'default' ) {
}, $tx->{$method}() ?: [] );

if ( count( $results ) !== count( $keys ) ) {
throw new Exception( 'Redis pipeline returned unexpected result' );
$tx->discard();
return array_fill_keys( $keys, false );
}

$execute_time = microtime( true ) - $start_time;
Expand Down Expand Up @@ -2270,7 +2272,8 @@ protected function set_multiple_at_once( array $data, $group = 'default', $expir
}, $tx->{$method}() ?: [] );

if ( count( $results ) !== count( $keys ) ) {
throw new Exception( 'Redis pipeline returned unexpected result' );
$tx->discard();
return array_fill_keys( $keys, false );
}

$results = array_combine( $keys, $results );
Expand Down

0 comments on commit 018c6d8

Please sign in to comment.