@@ 123-141 (lines=19) @@ | ||
120 | * @param int $value |
|
121 | * @return mixed |
|
122 | */ |
|
123 | public function increment($key, $value = 1) |
|
124 | { |
|
125 | $item = $this->getItem($key); |
|
126 | if ($item === false) { |
|
127 | $set_result = $this->set($key, $value); |
|
128 | if ($set_result === false) return false; |
|
129 | return $value; |
|
130 | } |
|
131 | ||
132 | $check_expire = $this->checkExpire($item); |
|
133 | if ($check_expire === false) return false; |
|
134 | ||
135 | $item['data'] += $value; |
|
136 | ||
137 | $result = $this->setItem($key, $item['data'], $item['time'], $item['expire']); |
|
138 | if ($result === false) return false; |
|
139 | ||
140 | return $item['data']; |
|
141 | } |
|
142 | ||
143 | /** |
|
144 | * 减法递增 |
|
@@ 149-168 (lines=20) @@ | ||
146 | * @param int $value |
|
147 | * @return mixed |
|
148 | */ |
|
149 | public function decrement($key, $value = 1) |
|
150 | { |
|
151 | $item = $this->getItem($key); |
|
152 | if ($item === false) { |
|
153 | $value = 0 - $value; |
|
154 | $set_result = $this->set($key, $value); |
|
155 | if ($set_result === false) return false; |
|
156 | return $value; |
|
157 | } |
|
158 | ||
159 | $check_expire = $this->checkExpire($item); |
|
160 | if ($check_expire === false) return false; |
|
161 | ||
162 | $item['data'] -= $value; |
|
163 | ||
164 | $result = $this->setItem($key, $item['data'], $item['time'], $item['expire']); |
|
165 | if ($result === false) return false; |
|
166 | ||
167 | return $item['data']; |
|
168 | } |
|
169 | ||
170 | /** |
|
171 | * 删除一个key,同事会删除缓存文件 |