Skip to content

Commit 94a2809

Browse files
committed
Merge pull request #13 from EagleWu/patch-1
修复对缓存数据对Array/Object类型支持
2 parents c7f124b + eab263d commit 94a2809

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Extend/Driver/Cache/CacheRedis.class.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public function __construct($options=array()) {
5656
*/
5757
public function get($name) {
5858
N('cache_read',1);
59-
return $this->handler->get($this->options['prefix'].$name);
59+
$value = $this->handler->get($this->options['prefix'].$name);
60+
$jsonData = json_decode( $value, true );
61+
return ($jsonData === NULL) ? $value : $jsonData; //检测是否为JSON数据 true 返回JSON解析数组, false返回源数据
6062
}
6163

6264
/**
@@ -73,6 +75,8 @@ public function set($name, $value, $expire = null) {
7375
$expire = $this->options['expire'];
7476
}
7577
$name = $this->options['prefix'].$name;
78+
//对数组/对象数据进行缓存处理,保证数据完整性
79+
$value = (is_object($value) || is_array($value)) ? json_encode($value) : $value;
7680
if(is_int($expire)) {
7781
$result = $this->handler->setex($name, $expire, $value);
7882
}else{

0 commit comments

Comments
 (0)