Redis.class.php的BUG

浏览:1855 发布日期:2015/04/22
3.2.3 - 严重 - 已关闭
缓存用REDIS。
实际编写代码中。如果想使用SQL的缓存.
如:$fooModel->cache(true, 100)->select();
会报错。

原因如下:
Model.class.php中
select函数,第508到515行, if(isset($options['cache'])){
            $cache  =   $options['cache'];
            $key    =   is_string($cache['key'])?$cache['key']:md5(serialize($options));
            $data   =   S($key,'',$cache);
            if(false !== $data){
                return $data;
            }
        }       


S函数执行时候,会有$cache参数[形参为$options],$cache为数组,且不为空。
而S函数所在的functions.php中。

第1026行,        $cache      =   Think\Cache::getInstance($type,$options);单例模式,实例化CACHE类时,会传递$options

Cache.class
第59行,依旧会传递$options参数。


而Redis类中。
第29行到36行。

只有$options不为空是,才会把host,port等的键值对追加进去。
而事实情况是,options不为空。

所以,代码应该改为: $options = array_merge(array (
                'host'          => C('REDIS_HOST') ? C('REDIS_HOST') : '127.0.0.1',
                'port'          => C('REDIS_PORT') ? C('REDIS_PORT') : 6379,
                'timeout'       => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false,
                'persistent'    => false,
            ), $options);
提醒大家用REDIS出现问题的朋友注意。







评论()
后面还有条评论,点击查看>>