Update Redis.php

修改缓存中的redis驱动不支持数组或对象数据存储的bug
This commit is contained in:
xiaobo.sun
2016-03-07 14:47:05 +08:00
parent 440658b2e4
commit 6b10e12202

View File

@@ -65,7 +65,10 @@ class Redis
public function get($name)
{
Cache::$readTimes++;
return $this->handler->get($this->options['prefix'] . $name);
$value = $this->handler->get($this->options['prefix'] . $name);
$jsonData = json_decode( $value, true );
// 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson<xiaobo.sun@qq.com>
return ($jsonData === null) ? $value : $jsonData;
}
/**
@@ -83,6 +86,8 @@ class Redis
$expire = $this->options['expire'];
}
$name = $this->options['prefix'] . $name;
//对数组/对象数据进行缓存处理,保证数据完整性 byron sampson<xiaobo.sun@qq.com>
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
if (is_int($expire)) {
$result = $this->handler->setex($name, $expire, $value);
} else {