mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进自增缓存
原来的方式在step为负数时会报错,并且在没有这个键值对时不会自动创建。现在的方式,避免了这个两个问题。
This commit is contained in:
11
library/think/cache/driver/Memcached.php
vendored
11
library/think/cache/driver/Memcached.php
vendored
@@ -115,7 +115,14 @@ class Memcached
|
||||
*/
|
||||
public function inc($name, $step = 1)
|
||||
{
|
||||
return $this->handler->increment($this->options['prefix'] . $name, $step);
|
||||
$oldValue = $this->handler->get($this->options['prefix'] . $name);
|
||||
$value = $oldValue + $step;
|
||||
$res = $this->handler->set($this->options['prefix'] . $name, $value);
|
||||
if (!$res) {
|
||||
return false;
|
||||
} else {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -129,7 +136,7 @@ class Memcached
|
||||
{
|
||||
$oldValue = $this->handler->get($this->options['prefix'] . $name);
|
||||
$value = $oldValue - $step;
|
||||
$res = $this->handler->set($this->options['prefix'] . $name, $oldValue - $step);
|
||||
$res = $this->handler->set($this->options['prefix'] . $name, $value);
|
||||
if (!$res) {
|
||||
return false;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user