-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRedisDAO.class.php
More file actions
executable file
·44 lines (39 loc) · 995 Bytes
/
RedisDAO.class.php
File metadata and controls
executable file
·44 lines (39 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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;
}
}
}