Commit 8daf8dc4 authored by Erick Hitter's avatar Erick Hitter
Browse files

Move Redis connection to its own function, for clarity.

parent 0ca5e34c
...@@ -107,18 +107,13 @@ function wp_redis_cache_get_clean_url( $secret ) { ...@@ -107,18 +107,13 @@ function wp_redis_cache_get_clean_url( $secret ) {
} }
/** /**
* BEGIN CACHING LOGIC * Establish a connection to the Redis server
*
* Will try the PECL module first, then fall back to PRedis
*
* @return object
*/ */
function wp_redis_cache_connect_redis() {
// Set proper IP for proxied requests
wp_redis_cache_handle_cdn_remote_addressing();
// Ensure WP uses a theme (this is normally set in index.php)
if ( ! defined( 'WP_USE_THEMES' ) ) {
define( 'WP_USE_THEMES', true );
}
try {
// check if PECL Extension is available // check if PECL Extension is available
if ( class_exists( 'Redis' ) ) { if ( class_exists( 'Redis' ) ) {
if ( $GLOBALS['wp_redis_cache_config']['debug'] ) { if ( $GLOBALS['wp_redis_cache_config']['debug'] ) {
...@@ -143,6 +138,25 @@ try { ...@@ -143,6 +138,25 @@ try {
) ); ) );
} }
return $redis;
}
/**
* BEGIN CACHING LOGIC
*/
// Set proper IP for proxied requests
wp_redis_cache_handle_cdn_remote_addressing();
// Ensure WP uses a theme (this is normally set in index.php)
if ( ! defined( 'WP_USE_THEMES' ) ) {
define( 'WP_USE_THEMES', true );
}
try {
// Establish connection with Redis server
$redis = wp_redis_cache_connect_redis();
//Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment //Either manual refresh cache by adding ?refresh=secret_string after the URL or somebody posting a comment
if ( wp_redis_cache_refresh_has_secret( $GLOBALS['wp_redis_cache_config']['secret_string'] ) || wp_redis_cache_request_has_secret( $GLOBALS['wp_redis_cache_config']['secret_string'] ) || wp_redis_cache_is_remote_page_load( $GLOBALS['wp_redis_cache_config']['current_url'], $GLOBALS['wp_redis_cache_config']['server_ip'] ) ) { if ( wp_redis_cache_refresh_has_secret( $GLOBALS['wp_redis_cache_config']['secret_string'] ) || wp_redis_cache_request_has_secret( $GLOBALS['wp_redis_cache_config']['secret_string'] ) || wp_redis_cache_is_remote_page_load( $GLOBALS['wp_redis_cache_config']['current_url'], $GLOBALS['wp_redis_cache_config']['server_ip'] ) ) {
if ( $GLOBALS['wp_redis_cache_config']['debug'] ) { if ( $GLOBALS['wp_redis_cache_config']['debug'] ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment