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

Allow timeout to be set via CACHE_TIMEOUT env var. #467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,9 @@ public function build_client_parameters( $redis_server ) {
$port = 6379;
// Default Redis database number.
$database = 0;
// Default timeout in ms.
// I multiplied this by 1000 so we'd have a common measure of ms instead of s and ms, need to make sure this gets divided by 1000.
$timeout = 1000;

if ( empty( $redis_server ) ) {
// Attempt to automatically load Pantheon's Redis config from the env.
Expand All @@ -1258,6 +1261,7 @@ public function build_client_parameters( $redis_server ) {
// @phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
'auth' => ! empty( $_SERVER['CACHE_PASSWORD'] ) ? $_SERVER['CACHE_PASSWORD'] : null,
'database' => ! empty( $_SERVER['CACHE_DB'] ) ? intval( $_SERVER['CACHE_DB'] ) : $database,
'timeout' => isset( $_SERVER['CACHE_TIMEOUT'] ) ? intval( $_SERVER['CACHE_TIMEOUT'] ) : $timeout,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check's current position in the Pantheon config conditional is a problem, as it only would get used if config set by the Pantheon env exists (CACHE_HOST et.al). Since this is not a config value Pantheon envs set, better to move it outside of the current block (probably up at 1250?) making this more portable.

];
} else {
$redis_server = [
Expand All @@ -1277,7 +1281,7 @@ public function build_client_parameters( $redis_server ) {
$defaults = [
'host' => $redis_server['host'],
'port' => $port,
'timeout' => 1000, // I multiplied this by 1000 so we'd have a common measure of ms instead of s and ms, need to make sure this gets divided by 1000.
'timeout' => $timeout,
'retry_interval' => 100,
];
// 1s timeout, 100ms delay between reconnections.
Expand Down