标签 redis 下的文章

SeaCMS修改文件缓存为Redis缓存系统

编辑 /include/common.func.php 文件第1514行,将

function setCache($p_cacheName,$sql="",$arr=""){
    global $dsql,$cfg_iscache,$cfg_cachetime,$cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$p_cacheName.'.inc';
    $mintime = time() - $cfg_cachetime*60;
    if(!file_exists($cacheFile) || ( file_exists($cacheFile) && ($mintime > filemtime($cacheFile)))){
        if (!empty($sql)){
        $dsql->SetQuery($sql);
        $dsql->Execute('hw');
        $cacher=array();
            while($cache=$dsql->GetObject('hw'))
            {
            $cacher[]=$cache;
            }
        }else{
            $cacher=$arr;
        }
        if (!empty($p_cacheName)){
            $fp = fopen($cacheFile,'w') or die("Write Cache File Error! ");
            fwrite($fp,serialize($cacher));
            fclose($fp);
        }
        unset($cacher);
    }
}

function getCache($p_cacheName){
    global $cfg_cachemark;
    $cacheFile=sea_ROOT.'/data/cache/'.$cfg_cachemark.$p_cacheName.'.inc';
    if(file_exists($cacheFile)){
        return unserialize(file_get_contents($cacheFile));
    }else{
        return array();
    }
}

修改为

function setCache($p_cacheName,$sql="",$arr=""){
        global $dsql,$cfg_iscache,$cfg_cachetime,$cfg_cachemark;
        $p_cacheName=$cfg_cachemark.$p_cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        $ttl=$redis->TTL($p_cacheName);
        if ($ttl < 1 ){
                if (!empty($sql)){
                        $dsql->SetQuery($sql);
                        $dsql->Execute('hw');
                        $cacher=array();
                  while($cache=$dsql->GetObject('hw'))
                        {
                        $cacher[]=$cache;
                        }
                }else{
                        $cacher=$arr;
                }
                if (!empty($p_cacheName)){
                        $redis->SETEX($p_cacheName,$cfg_cachetime*60,serialize($cacher));
                }
                unset($cacher);
        }
}

function getCache($p_cacheName){
        global $cfg_cachemark;
        $p_cacheName=$cfg_cachemark.$p_cacheName;
        $redis = new redis();  
        $redis->connect('127.0.0.1', 6379);  
        $ttl=$redis->TTL($p_cacheName);
        if ($ttl > 0 ){
                return unserialize($redis->GET($p_cacheName));
        }else{
                return array();
        }
}

- 阅读剩余部分 -