From 6b10e12202aeb49acc751ec6d16bbf6ffcb587a2 Mon Sep 17 00:00:00 2001 From: "xiaobo.sun" <5ini99@sohu.com> Date: Mon, 7 Mar 2016 14:47:05 +0800 Subject: [PATCH] Update Redis.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改缓存中的redis驱动不支持数组或对象数据存储的bug --- library/think/cache/driver/Redis.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index b5625c5c..8dbce0e5 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -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 + return ($jsonData === null) ? $value : $jsonData; } /** @@ -83,6 +86,8 @@ class Redis $expire = $this->options['expire']; } $name = $this->options['prefix'] . $name; + //对数组/对象数据进行缓存处理,保证数据完整性 byron sampson + $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; if (is_int($expire)) { $result = $this->handler->setex($name, $expire, $value); } else {