mirror of
https://github.com/newnius/YAO-portal.git
synced 2025-12-13 09:06:43 +00:00
init & add agent & add job
This commit is contained in:
44
util4p/RedisDAO.class.php
Executable file
44
util4p/RedisDAO.class.php
Executable file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
require_once('CRObject.class.php');
|
||||
if (!class_exists('Predis\Client')) {
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
var_dump('predis (github.com/nrk/predis.git) required');
|
||||
exit;
|
||||
}
|
||||
|
||||
class RedisDAO
|
||||
{
|
||||
private static $scheme = 'tcp';
|
||||
private static $host = 'localhost';
|
||||
private static $port = 6379;
|
||||
private static $show_error = false;
|
||||
|
||||
public static function configure(CRObject $config)
|
||||
{
|
||||
self::$scheme = $config->get('scheme', self::$scheme);
|
||||
self::$host = $config->get('host', self::$host);
|
||||
self::$port = $config->getInt('port', self::$port);
|
||||
self::$show_error = $config->getBool('show_error', self::$show_error);
|
||||
}
|
||||
|
||||
public static function instance()
|
||||
{
|
||||
try {
|
||||
$redis = new Predis\Client(
|
||||
array(
|
||||
'scheme' => RedisDAO::$scheme,
|
||||
'host' => RedisDAO::$host,
|
||||
'port' => RedisDAO::$port
|
||||
)
|
||||
);
|
||||
$redis->connect();
|
||||
return $redis;
|
||||
} catch (Exception $e) {
|
||||
if (self::$show_error)
|
||||
var_dump($e->getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user