From dd1f1d49ab8a0f0e75828a7a54f104ec905483c8 Mon Sep 17 00:00:00 2001 From: zzpuser Date: Wed, 3 Aug 2016 19:32:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BA=86=E5=BB=B6=E8=BF=9F?= =?UTF-8?q?=E9=80=92=E5=A2=9E=E5=87=8F=E5=90=8E=E4=B8=8D=E8=83=BD=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E7=9A=84=E8=AE=A1=E6=95=B0=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E3=80=81=E4=BF=AE=E6=AD=A3=E4=BA=86=E5=BB=B6=E8=BF=9F=E9=80=92?= =?UTF-8?q?=E5=87=8F=EF=BC=8C=E6=95=B0=E5=80=BC=E5=B0=8F=E4=BA=8E=E9=9B=B6?= =?UTF-8?q?=E6=97=B6=E4=B8=8D=E8=83=BD=E9=80=92=E5=87=8F=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.之前由于递增减的键值对的键是没有加前缀的,而移除这个记录增减的键值对时移除的是加前缀的,所以会导致移除时失败,最终造成递增减数值错误。 2.由于Memcached的decrement方法递减到0以后就不会再减小了,所以这里就会造成递减的数值不对。只好自己写一个递减的方法了。 该方法说明详见http://php.net/manual/zh/memcached.decrement.php --- 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 2eec2ea2..f67ea8f5 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -115,7 +115,7 @@ class Memcached */ public function inc($name, $step = 1) { - return $this->handler->increment($name, $step); + return $this->handler->increment($this->options['prefix'] . $name, $step); } /** @@ -127,7 +127,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, $oldValue - $step); + if (!$res) { + return false; + } else { + return $value; + } } /**