Predis.php in Redis 7
File
lib/Redis/Client/Predis.php
View source
<?php
if (!class_exists('Predis\\Client')) {
if (!defined('PREDIS_BASE_PATH')) {
$search = DRUPAL_ROOT . '/sites/all/libraries/predis/lib/';
if (is_dir($search)) {
define('PREDIS_BASE_PATH', $search);
}
else {
throw new Exception("PREDIS_BASE_PATH constant must be set, Predis library must live in sites/all/libraries/predis.");
}
}
spl_autoload_register(function ($class) {
$file = PREDIS_BASE_PATH . strtr($class, '\\', '/') . '.php';
if (file_exists($file)) {
require $file;
return TRUE;
}
});
}
class Redis_Client_Predis implements Redis_Client_Interface {
public function getClient($host = NULL, $port = NULL, $base = NULL) {
$connectionInfo = array(
'host' => $host,
'port' => $port,
'database' => $base,
);
foreach ($connectionInfo as $key => $value) {
if (!isset($value)) {
unset($connectionInfo[$key]);
}
}
return new Predis\Client($connectionInfo);
}
public function getName() {
return 'Predis';
}
}