Skip to content

Commit

Permalink
Respect WP_REDIS_FLUSH_TIMEOUT
Browse files Browse the repository at this point in the history
  • Loading branch information
yatsukhnenko committed Mar 6, 2024
1 parent 1c4f986 commit 704ac36
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions includes/object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1825,9 +1825,32 @@ protected function lua_flush_closure( $salt, $escape = true ) {
$script = 'redis.replicate_commands()' . "\n" . $script;
}

$args = $this->is_predis() ? [ $script, 0 ] : [ $script ];
if ( $this->is_predis() ) {
$args = [ $script, 0 ];
if ( defined('WP_REDIS_FLUSH_TIMEOUT') ) {
$timeout = $this->redis->getConnection()->getParameters()->read_write_timeout ?? ini_get( 'default_socket_timeout' );
// $timeout = stream_context_get_options($this->redis->getConnection()->getResource())['socket']['timeout'] ?? ini_get( 'default_socket_timeout' );
stream_set_timeout($this->redis->getConnection()->getResource(), WP_REDIS_FLUSH_TIMEOUT);
}
} else {
$args = [ $script ];
if ( defined('WP_REDIS_FLUSH_TIMEOUT') ) {
$timeout = $this->redis->getOption(Redis::OPT_READ_TIMEOUT);
$this->redis->setOption(Redis::OPT_READ_TIMEOUT, WP_REDIS_FLUSH_TIMEOUT);
}
}

return call_user_func_array( [ $this->redis, 'eval' ], $args );
$result = call_user_func_array( [ $this->redis, 'eval' ], $args );

if ( isset($timeout) ) {
if ( $this->is_predis() ) {
stream_set_timeout($this->redis->getConnection()->getResource(), $timeout);
} else {
$this->redis->setOption(Redis::OPT_READ_TIMEOUT, $timeout);
}
}

return $result;
};
}

Expand Down

0 comments on commit 704ac36

Please sign in to comment.