From 3c0e97767d4b5cf138c3f31d0b1fff011ebc2b2d Mon Sep 17 00:00:00 2001 From: zzpuser Date: Wed, 3 Aug 2016 23:21:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=E8=87=AA=E5=A2=9E=E7=BC=93?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 原来的方式在step为负数时会报错,并且在没有这个键值对时不会自动创建。现在的方式,避免了这个两个问题。 --- library/think/cache/driver/Memcached.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index f67ea8f5..c09f4bc8 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -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 {