分享

redis设定有效时间

 昵称28012971 2015-09-30
   
       //$uid = passport_check();//用户id
       //$news_id = mysql_real_escape_string($_GET['news_id']);//新闻id
       if(empty($news_id) || !$news_id){
            html_json_exit(501, '参数必须存在');
       }
       $ip = Search::getClientIp();
       $conn = "user";
       $key = $ip.'_pv_'.$news_id;
       $recv = $ip;
       $get_ip = MRedis::hGet($conn, $key, $recv);
       
       if(!$get_ip){
          $last = strtotime(date('Y-m-d 23:59:59'));
          $diff = $last -G_TIME;
          $rt = MRedis::hSet($conn, $key, $recv, $ip,$diff);
          //增加pv值到数据库里边去
          $news_info = News::findone($news_id,'pv,cont');
          $news_info = $news_info['rows'][0];
          
          $where = array(
            'pv'=>($news_info['pv'])+1
          );
          $bool = News::edit($news_id,$where);
          
          $news_info['pv'] = $news_info['pv']+1;
          return  $news_info;
        }else{
          $news_info = News::findone($news_id,'pv,cont');
          $news_info = $news_info['rows'][0];
          return $news_info;
        }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多