-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmc.php
88 lines (73 loc) · 1.71 KB
/
mc.php
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
/**
* Created by PhpStorm.
* User: Youi
* Date: 2015-12-08
* Time: 21:18
*/
class mc {
/**
* @var Memcached|null
*/
private $m = null;
public function __construct() {
$this->m = new Memcached();
$this->m->setOption(Memcached::OPT_COMPRESSION, false);
$this->m->setOption(Memcached::OPT_SERIALIZER, Memcached::SERIALIZER_IGBINARY);
}
/**
* get for json
* @param string $recordKey
* @return mixed
*/
public function getInfo($recordKey) {
return $this->m->get($recordKey);
}
/**
* set for json, 24 hour, identical to singleSet method
* @param string $recordKey
* @param mixed $recordData
* @return bool
*/
public function setInfo($recordKey, &$recordData) {
return $this->m->set($recordKey, $recordData, 3600 * 24);
}
/**
* multi get method
* @param array $keys
* @return mixed
*/
public function batchGet($keys) {
return @$this->m->getMulti($keys);
}
/**
* multi set method
* @param array $dataArray
* @return bool
*/
public function batchSet($dataArray) {
return $this->m->setMulti($dataArray, 3600 * 24);
}
/**
* set method
* @param string $key
* @param mixed $data
* @return bool
*/
public function singleSet($key, &$data) {
return $this->m->set($key, $data, 3600 * 24);
}
/**
* renew caches
* @param array $keys
* @return bool
*/
public function touchKeys($keys) {
foreach ($keys as $key) {
if (!$this->m->touch($key, 3600 * 24)) {
return false;
}
}
return true;
}
}