From c47961163cb9d477ac31f782dddbb5c7eed3f838 Mon Sep 17 00:00:00 2001 From: Erick Hitter <ehitter@gmail.com> Date: Mon, 3 Mar 2014 20:30:45 -0800 Subject: [PATCH] Add support for Redis PECL library Fixes #1 --- object-cache.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/object-cache.php b/object-cache.php index cae9758..10152a1 100644 --- a/object-cache.php +++ b/object-cache.php @@ -249,8 +249,9 @@ class WP_Object_Cache { * @param null $persistent_id To create an instance that persists between requests, use persistent_id to specify a unique ID for the instance. */ public function __construct() { - require_once 'predis/autoload.php'; + global $blog_id, $table_prefix; + // General Redis settings $redis = array( 'host' => '127.0.0.1', 'port' => 6379, @@ -266,10 +267,20 @@ class WP_Object_Cache { $redis['database'] = WP_REDIS_BACKEND_DB; } - $this->redis = new Predis\Client( $redis ); - unset( $redis ); + // Use Redis PECL library if available, otherwise default to bundled Predis library + if ( class_exists( 'Redis' ) ) { + $this->redis = new Redis(); + $this->redis->connect( $redis['host'], $redis['port'] ); - global $blog_id, $table_prefix; + if ( isset( $redis['database'] ) ) { + $this->redis->select( $redis['database'] ); + } + } else { + require_once 'predis/autoload.php'; + $this->redis = new Predis\Client( $redis ); + } + + unset( $redis ); /** * This approach is borrowed from Sivel and Boren. Use the salt for easy cache invalidation and for -- GitLab