Skip to content
Draft
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
35 changes: 26 additions & 9 deletions object-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,27 @@
*/
public $last_triggered_error = '';

/**
* The Redis client instance
*
* @var Redis|RedisCluster|Predis\Client|null
*/
public $redis = null;

/**
* Error message when Redis cannot connect
*
* @var string
*/
public $missing_redis_message = '';

/**
* Global prefix for cache keys
*
* @var string
*/
public $global_prefix = '';

/**
* Whether or not to use true cache groups, instead of flattening.
*
Expand Down Expand Up @@ -1257,11 +1278,11 @@
$redis_server = [
// Don't use WP methods to sanitize the host due to plugin loading issues with other caching methods.
// @phpcs:ignore WordPressVIPMinimum.Functions.StripTags.StripTagsOneParameter,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
'host' => strip_tags( $_SERVER['CACHE_HOST'] ),

Check warning on line 1281 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.Security.ValidatedSanitizedInput.MissingUnslash

$_SERVER['CACHE_HOST'] not unslashed before sanitization. Use wp_unslash() or similar
'port' => ! empty( $_SERVER['CACHE_PORT'] ) ? intval( $_SERVER['CACHE_PORT'] ) : $port,
// Don't attempt to sanitize passwords as this can break authentication.
// @phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
'auth' => ! empty( $_SERVER['CACHE_PASSWORD'] ) ? $_SERVER['CACHE_PASSWORD'] : null,

Check warning on line 1285 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.Security.ValidatedSanitizedInput.MissingUnslash

$_SERVER['CACHE_PASSWORD'] not unslashed before sanitization. Use wp_unslash() or similar
'database' => ! empty( $_SERVER['CACHE_DB'] ) ? intval( $_SERVER['CACHE_DB'] ) : $database,
];
} else {
Expand All @@ -1276,7 +1297,7 @@
if ( file_exists( $redis_server['host'] ) && 'socket' === filetype( $redis_server['host'] ) ) { // unix socket connection.
// port must be null or socket won't connect.
unset( $redis_server['port'] );
$port = -1;
$port = null;
}

$defaults = [
Expand Down Expand Up @@ -1335,10 +1356,8 @@
$redis->$method( $client_parameters[ $key ] );
} catch ( RedisException $e ) {

/**
* PhpRedis throws an Exception when it fails a server call.
* To prevent WordPress from fataling, we catch the Exception.
*/
// PhpRedis throws an Exception when it fails a server call.
// To prevent WordPress from fataling, we catch the Exception.
Comment on lines +1359 to +1360

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment change will break Pantheon WP Coding Standards in 3.0

throw new Exception( $e->getMessage(), $e->getCode(), $e ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
}
Expand Down Expand Up @@ -1373,10 +1392,8 @@
return $retval;
} catch ( Exception $e ) {
$retry_exception_messages = $this->retry_exception_messages();
/**
* PhpRedis throws an Exception when it fails a server call.
* To prevent WordPress from fataling, we catch the Exception.
*/
// PhpRedis throws an Exception when it fails a server call.
// To prevent WordPress from fataling, we catch the Exception.
Comment on lines +1395 to +1396

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔢 same as above

if ( $this->exception_message_matches( $e->getMessage(), $retry_exception_messages ) ) {

$this->_exception_handler( $e );
Expand All @@ -1402,7 +1419,7 @@
$col1 = 'option_name';
$col2 = 'option_value';
}
$wpdb->query( "INSERT IGNORE INTO {$table} ({$col1},{$col2}) VALUES ('wp_redis_do_redis_failback_flush',1)" );

Check warning on line 1422 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.DB.PreparedSQL.InterpolatedNotPrepared

Use placeholders and $wpdb->prepare(); found interpolated variable {$col1} at "INSERT IGNORE INTO {$table} ({$col1},{$col2}) VALUES ('wp_redis_do_redis_failback_flush',1)"

Check warning on line 1422 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.DB.PreparedSQL.InterpolatedNotPrepared

Use placeholders and $wpdb->prepare(); found interpolated variable {$table} at "INSERT IGNORE INTO {$table} ({$col1},{$col2}) VALUES ('wp_redis_do_redis_failback_flush',1)"

Check warning on line 1422 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.DB.DirectDatabaseQuery.NoCaching

Direct database call without caching detected. Consider using wp_cache_get() / wp_cache_set() or wp_cache_delete().

Check warning on line 1422 in object-cache.php

View workflow job for this annotation

GitHub Actions / wporg-validation

WordPress.DB.DirectDatabaseQuery.DirectQuery

Use of a direct database call is discouraged.
$this->do_redis_failback_flush = true;
}

Expand Down
Loading