From 2d61cde943874795453abc47a57968baac7f8df9 Mon Sep 17 00:00:00 2001 From: thinkphp Date: Fri, 17 Nov 2017 14:27:36 +0800 Subject: [PATCH] =?UTF-8?q?Redis=E7=BC=93=E5=AD=98=E9=A9=B1=E5=8A=A8?= =?UTF-8?q?=E6=94=B9=E7=94=A8serialize=E5=BA=8F=E5=88=97=E5=8C=96=E6=9B=BF?= =?UTF-8?q?=E4=BB=A3json=E5=BA=8F=E5=88=97=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/cache/driver/Redis.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/library/think/cache/driver/Redis.php b/library/think/cache/driver/Redis.php index f5d30042..b3002c1e 100644 --- a/library/think/cache/driver/Redis.php +++ b/library/think/cache/driver/Redis.php @@ -83,9 +83,8 @@ class Redis extends Driver if (is_null($value) || false === $value) { return $default; } - $jsonData = json_decode($value, true); - // 检测是否为JSON数据 true 返回JSON解析数组, false返回源数据 byron sampson - return (null === $jsonData) ? $value : $jsonData; + + return unserialize($value); } /** @@ -107,9 +106,8 @@ class Redis extends Driver if ($this->tag && !$this->has($name)) { $first = true; } - $key = $this->getCacheKey($name); - //对数组/对象数据进行缓存处理,保证数据完整性 byron sampson - $value = (is_object($value) || is_array($value)) ? json_encode($value) : $value; + $key = $this->getCacheKey($name); + $value = serialize($value); if (is_int($expire) && $expire) { $result = $this->handler->setex($key, $expire, $value); } else {