Skip to content

Commit eab263d

Browse files
committed
修复对存储数据对Array/Object类型数据支持
缓存类库 DB.class.php 不对需要缓存的数据进行验证,扩展类库中需自行扩展处理。
1 parent c7f124b commit eab263d

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)