Commit 8da7c83f authored by cuiweifeng's avatar cuiweifeng

update : delete json_decode

parent 5f2c1cf1
......@@ -74,36 +74,6 @@ class CacheUtil
return call_user_func_array([$this->handler, $method], $args);
}
/**
* 获取原始数据
* @param $key
* @return mixed
*/
public function getUnChange($key, $prefix = ''){
return $this->handler->get($this->getCacheKey($prefix, $key));
}
/**
* 保存原始数据
* @param $key
* @param $value
* @param $expire
* @return mixed
*/
public function setUnChange($key , $value , $expire = null, $prefix = ''){
if (is_null($expire)) {
// $expire = $this->expire;
return false;
}
$key = $this->getCacheKey($prefix, $key);
if (is_int($expire) && $expire) {
$result = $this->handler->setex($key, $expire, $value);
} else {
$result = $this->handler->set($key, $value);
}
return $result;
}
/**
* 读取缓存
* @access public
......@@ -117,9 +87,7 @@ class CacheUtil
if (is_null($value) || false === $value) {
return $default;
}
$jsonData = json_decode($value, true);
// 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据
return (null === $jsonData) ? $value : $jsonData;
return $value;
}
/**
......@@ -129,24 +97,13 @@ class CacheUtil
* @param mixed $default 默认值
* @return mixed
*/
public function gets($keys, $prefix = '', $default = false)
public function gets($keys, $prefix = '')
{
if(empty($keys) || !is_array($keys)) {
return $default;
return false;
}
$keys = array_values($keys);
$values = $this->handler->mGet($this->getCacheKey($prefix, $keys));
if (is_null($values) || false === $values) {
return $default;
}
$result = [];
foreach((array)$values as $i => $value) {
if($value !== false) {
$jsonData = json_decode($value, true);
$result[$keys[$i]] = (null === $jsonData) ? $value : $jsonData;
}
}
return $result;
return $this->handler->mGet($this->getCacheKey($prefix, $keys));
}
/**
......@@ -165,7 +122,6 @@ class CacheUtil
}
$key = $this->getCacheKey($prefix, $key);
//对数组/对象数据进行缓存处理,保证数据完整性
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
if (is_int($expire) && $expire) {
$result = $this->handler->setex($key, $expire, $value);
} else {
......@@ -189,7 +145,6 @@ class CacheUtil
$this->handler->multi();
foreach($items as $key => $value) {
$key = $this->getCacheKey($prefix, $key);
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
$this->handler->setex($key, $expire, $value);
}
return $this->handler->exec();
......@@ -210,7 +165,6 @@ class CacheUtil
}
$key = $this->getCacheKey($prefix, $key);
//对数组/对象数据进行缓存处理,保证数据完整性
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
if(is_int($expire) && $expire) {
$result = $this->handler->setenx($key, $expire, $value);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment