Commit 48d20e08 authored by 顾文旭's avatar 顾文旭

fix redis

parent b25a9123
......@@ -24,7 +24,7 @@ class CacheUtil
const EXPIRE_AFTER_THREE_DAYS = 259200;
const EXPIRE_AFTER_FIFTEEN_DAYS = 1296000;
const EXPIRE_AFTER_ONE_MONTH = 2592000;
private static $instances = [];
private $handler = null;
private $expire = 86400; //@todo 讨论一下,如果不设置有效时间,默认1天,不允许设置长期有效
......@@ -40,7 +40,7 @@ class CacheUtil
* @param boolean $master
* @return mixed
*/
public static function getInstance($serverName = '', array $options = [])
public static function getInstance($serverName = '', array $options = [])
{
if (empty($serverName)) {
return null;
......@@ -53,7 +53,7 @@ class CacheUtil
if (isset(self::$instances[$instancesKey])) {
return self::$instances[$instancesKey];
}
return self::$instances[$instancesKey] = new Self($serverName, $options);
}
......@@ -87,7 +87,7 @@ class CacheUtil
if (is_null($value) || false === $value) {
return $default;
}
return $value;
return json_decode($value);
}
/**
......@@ -123,9 +123,9 @@ class CacheUtil
$key = $this->getCacheKey($prefix, $key);
//对数组/对象数据进行缓存处理,保证数据完整性
if (is_int($expire) && $expire) {
$result = $this->handler->setex($key, $expire, $value);
$result = $this->handler->setex($key, $expire, json_encode($value));
} else {
$result = $this->handler->set($key, $value);
$result = $this->handler->set($key, json_encode($value));
}
return $result;
}
......@@ -282,7 +282,7 @@ class CacheUtil
$keyArr[] = $prefix . $val;
}
return $keyArr;
}
}
return $prefix . $key;
}
}
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