Commit c4796116 authored by Erick Hitter's avatar Erick Hitter
Browse files

Add support for Redis PECL library

Fixes #1
parent 452bcba0
......@@ -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
......
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