修正redis驱动

This commit is contained in:
thinkphp
2017-11-21 17:10:52 +08:00
parent ea36fdfbe9
commit 23102de352
2 changed files with 16 additions and 8 deletions

View File

@@ -132,8 +132,12 @@ class Redis extends Driver
*/
public function inc($name, $step = 1)
{
$key = $this->getCacheKey($name);
return $this->handler->incrby($key, $step);
if ($this->has($name)) {
$value = $this->get($name) + $step;
} else {
$value = $step;
}
return $this->set($name, $value, 0) ? $value : false;
}
/**
@@ -145,8 +149,12 @@ class Redis extends Driver
*/
public function dec($name, $step = 1)
{
$key = $this->getCacheKey($name);
return $this->handler->decrby($key, $step);
if ($this->has($name)) {
$value = $this->get($name) - $step;
} else {
$value = -$step;
}
return $this->set($name, $value, 0) ? $value : false;
}
/**