diff --git a/library/think/cache/driver/Memcache.php b/library/think/cache/driver/Memcache.php index 62f98bce..aacba930 100644 --- a/library/think/cache/driver/Memcache.php +++ b/library/think/cache/driver/Memcache.php @@ -109,6 +109,7 @@ class Memcache */ public function inc($name, $step = 1) { + $name = $this->options['prefix'] . $name; return $this->handler->increment($name, $step); } @@ -121,7 +122,14 @@ class Memcache */ public function dec($name, $step = 1) { - return $this->handler->decrement($name, $step); + $name = $this->options['prefix'] . $name; + $value = $this->handler->get($name) - $step; + $res = $this->handler->set($name, $value); + if (!$res) { + return false; + } else { + return $value; + } } /** diff --git a/library/think/cache/driver/Memcached.php b/library/think/cache/driver/Memcached.php index c09f4bc8..f260fec6 100644 --- a/library/think/cache/driver/Memcached.php +++ b/library/think/cache/driver/Memcached.php @@ -115,14 +115,8 @@ class Memcached */ public function inc($name, $step = 1) { - $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; - } + $name = $this->options['prefix'] . $name; + return $this->handler->increment($name, $step); } /** @@ -134,9 +128,9 @@ class Memcached */ public function dec($name, $step = 1) { - $oldValue = $this->handler->get($this->options['prefix'] . $name); - $value = $oldValue - $step; - $res = $this->handler->set($this->options['prefix'] . $name, $value); + $name = $this->options['prefix'] . $name; + $value = $this->handler->get($name) - $step; + $res = $this->handler->set($name, $value); if (!$res) { return false; } else { diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index 99f9583d..4caa3fb8 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -115,6 +115,7 @@ class Redis */ public function inc($name, $step = 1) { + $name = $this->options['prefix'] . $name; return $this->handler->incrby($name, $step); } @@ -127,6 +128,7 @@ class Redis */ public function dec($name, $step = 1) { + $name = $this->options['prefix'] . $name; return $this->handler->decrby($name, $step); } diff --git a/library/think/cache/driver/Wincache.php b/library/think/cache/driver/Wincache.php index e8e79b47..77fb74a4 100644 --- a/library/think/cache/driver/Wincache.php +++ b/library/think/cache/driver/Wincache.php @@ -94,6 +94,7 @@ class Wincache */ public function inc($name, $step = 1) { + $name = $this->options['prefix'] . $name; return wincache_ucache_inc($name, $step); } @@ -106,6 +107,7 @@ class Wincache */ public function dec($name, $step = 1) { + $name = $this->options['prefix'] . $name; return wincache_ucache_dec($name, $step); } diff --git a/library/think/cache/driver/Xcache.php b/library/think/cache/driver/Xcache.php index e58e5102..e012112f 100644 --- a/library/think/cache/driver/Xcache.php +++ b/library/think/cache/driver/Xcache.php @@ -94,6 +94,7 @@ class Xcache */ public function inc($name, $step = 1) { + $name = $this->options['prefix'] . $name; return xcache_inc($name, $step); } @@ -106,6 +107,7 @@ class Xcache */ public function dec($name, $step = 1) { + $name = $this->options['prefix'] . $name; return xcache_dec($name, $step); }