2

我正在尝试重新设置缓存,但每次我这样做时,过期时间都会保持有效。如何在不影响过期时间的情况下更新 redis 缓存。

$cache = Yii::app()->cache;
if($cache->get($md5)){
    $md5Values = $cache->get($md5);
    $md5Values['repetition'] +=1;
    $md5Values['priority'] = 2;var_dump($cache->get($md5));
    $cache->set($md5,$md5Values);
    if ($md5Values['repetition'] > 10 && $md5Values['repetition'] <= 1000){

        $md5Values['priority'] = 1;
        $cache->set($md5,$md5Values);
        var_dump($cache->get($md5));
        return  array('priority'=>1);
    } elseif ($md5Values['repetition'] > 1000){
        $md5Values['priority'] = 0;
        $cache->set($md5,$md5Values);
        return  array('priority'=>0);
    }
    return false;
}else{
    $cacheArray=array();
    $cacheArray['repetition'] = 1;
    $cacheArray['priority'] = 2;
    $cache->set($md5,$cacheArray,30);
    return false;
} 
4

0 回答 0