Merge pull request #238 from zzpuser/patch-8

修正了延迟递增减后不能清空的计数的问题、修正了延迟递减,数值小于零时不能递减的问题
This commit is contained in:
ThinkPHP
2016-08-05 04:53:47 -05:00
committed by GitHub

View File

@@ -115,7 +115,14 @@ class Memcached
*/
public function inc($name, $step = 1)
{
return $this->handler->increment($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;
}
}
/**
@@ -127,7 +134,14 @@ class Memcached
*/
public function dec($name, $step = 1)
{
return $this->handler->decrement($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;
}
}
/**