mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-08 15:42:48 +08:00
改进redis驱动
This commit is contained in:
22
library/think/cache/driver/Redis.php
vendored
22
library/think/cache/driver/Redis.php
vendored
@@ -85,7 +85,7 @@ class Redis extends Driver
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$result = unserialize($value);
|
$result = 0 === strpos($value, 'think_serialize:') ? unserialize(substr($value, 16)) : $value;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$result = $default;
|
$result = $default;
|
||||||
}
|
}
|
||||||
@@ -113,7 +113,7 @@ class Redis extends Driver
|
|||||||
$first = true;
|
$first = true;
|
||||||
}
|
}
|
||||||
$key = $this->getCacheKey($name);
|
$key = $this->getCacheKey($name);
|
||||||
$value = serialize($value);
|
$value = is_scalar($value) ? $value : 'think_serialize:' . serialize($value);
|
||||||
if (is_int($expire) && $expire) {
|
if (is_int($expire) && $expire) {
|
||||||
$result = $this->handler->setex($key, $expire, $value);
|
$result = $this->handler->setex($key, $expire, $value);
|
||||||
} else {
|
} else {
|
||||||
@@ -132,12 +132,9 @@ class Redis extends Driver
|
|||||||
*/
|
*/
|
||||||
public function inc($name, $step = 1)
|
public function inc($name, $step = 1)
|
||||||
{
|
{
|
||||||
if ($this->has($name)) {
|
$key = $this->getCacheKey($name);
|
||||||
$value = $this->get($name) + $step;
|
|
||||||
} else {
|
return $this->handler->incrby($key, $step);
|
||||||
$value = $step;
|
|
||||||
}
|
|
||||||
return $this->set($name, $value, 0) ? $value : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,12 +146,9 @@ class Redis extends Driver
|
|||||||
*/
|
*/
|
||||||
public function dec($name, $step = 1)
|
public function dec($name, $step = 1)
|
||||||
{
|
{
|
||||||
if ($this->has($name)) {
|
$key = $this->getCacheKey($name);
|
||||||
$value = $this->get($name) - $step;
|
|
||||||
} else {
|
return $this->handler->decrby($key, $step);
|
||||||
$value = -$step;
|
|
||||||
}
|
|
||||||
return $this->set($name, $value, 0) ? $value : false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user