connect($config['redis_host'], $config['redis_port']); if ($config['redis_pwd']) { $redis->auth($config['redis_pwd']); } if($config['redis_selectdb'] > 0){ $redis->select($config['redis_selectdb']); } //日期 $today = date('Y-m-d'); $yestodaytime = strtotime($today)-86400; $yestoday = date('Y-m-d',$yestodaytime); //$yestoday = $today;//测试临时用 //视频id 列表 $yestoday_video_key = $yestoday.'_video_list'; $yestoday_video_list = $redis->sMembers($yestoday_video_key); if(empty($yestoday_video_list)){ echo $yestoday_video_key.': empty';exit; } foreach($yestoday_video_list as $key => $video_id){ //准备数据 $date_pvuv = [ 'video_id' => $video_id, 'datetime' => $yestodaytime, ]; //昨日视频pv $yestoday_pv_key = $yestoday.'_video_pv_'.$video_id; $date_pvuv['video_pv'] = $redis->get($yestoday_pv_key); $redis->del($yestoday_pv_key); //昨日视频uv $yestoday_uv_key = $yestoday.'_video_uv_'.$video_id; $date_pvuv['video_uv'] = $redis->sCard($yestoday_uv_key); //数量 $redis->del($yestoday_uv_key); //写入数据 Db::name('video_pvuv')->where($date_pvuv)->delete(); Db::name('video_pvuv')->insertGetId($date_pvuv); } $redis->del($yestoday_video_key); } }