-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathtypecho_redis.class.php
More file actions
67 lines (57 loc) · 1.58 KB
/
typecho_redis.class.php
File metadata and controls
67 lines (57 loc) · 1.58 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
class typecho_redis implements TpCache
{
private static $_instance = null;
private $redis = null;
private $host = '127.0.0.1';
private $port = 11211;
private $expire = 86400;
private $auth = 'password';
private function __construct($option = null)
{
$this->host = $option->host;
$this->port = $option->port;
$this->auth = $option->auth;
$this->expire = $option->expire + 0;
$this->init($option);
}
static public function getInstance($option)
{
if (is_null(self::$_instance) || !isset(self::$_instance)) {
self::$_instance = new self($option);
}
return self::$_instance;
}
public function init($option)
{
try {
$this->redis = new Redis();
$this->redis->connect($this->host, $this->port);
if (!empty($this->auth)) {
$this->redis->auth($this->auth);
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
public function add($key, $value, $expire = null)
{
return $this->redis->set($key, $value, is_null($expire) ? $this->expire : $expire);
}
public function delete($key)
{
return $this->redis->delete($key);
}
public function set($key, $value, $expire = null)
{
return $this->redis->set($key, $value, is_null($expire) ? $this->expire : $expire);
}
public function get($key)
{
return $this->redis->get($key);
}
public function flush()
{
return $this->redis->flushDB();
}
}