麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 數(shù)據(jù)庫 > Redis > 正文

PHP 利用redis 做統(tǒng)計(jì)緩存mysql的壓力

2020-03-17 12:44:03
字體:
供稿:網(wǎng)友
PHP 利用redis 做統(tǒng)計(jì)緩存mysql的壓力,代碼如下:


  1. <?php 
  2.     header("Content-Type:text/html;charset=utf-8"); 
  3.     include 'lib/mysql.class.php'
  4.     $mysql_obj = mysql::getConn(); 
  5.     //redis  
  6.     $redis = new Redis(); 
  7.     $redis->pconnect('127.0.0.1', 6379); 
  8.  
  9.     if(isset($_SERVER['HTTP_REFERER'])){ 
  10.         $url_md5 = md5($_SERVER['HTTP_REFERER']); 
  11.     } 
  12.     $adve_key = 'adve';  
  13.     $adve_key_exists = 'adve_exists'
  14.     if(!$redis->exists($adve_key_exists)){ 
  15.         $list = $mysql_obj->fetch_array("select * from user_online_adve"); 
  16.         if($list){ 
  17.             foreach ($list as $key => $value) { 
  18.                 $url_hash = md5($value['adve_url']); 
  19.                 $adve_hash_key = $adve_key.":".$url_hash
  20.                 $id = $value['id']; 
  21.                 $redis->set($adve_hash_key,$id); 
  22.                 $redis->set($adve_key_exists,true); 
  23.                 //$redis->hmset($adve_hash_key, array('id' =>$id)); 
  24.                 //print_r($redis->get($adve_hash_key)); 
  25.             } 
  26.         } 
  27.     } 
  28.     $adve_new_key = $adve_key.':'.$url_md5
  29.     if($redis->exists($adve_new_key)){ 
  30.             $adve_plus = $adve_new_key.":plus" ; 
  31.  
  32.             if(!$redis->exists($adve_plus)){ 
  33.                 $redis->set($adve_plus,1);   
  34.             }else
  35.                 $redis->incr($adve_plus); 
  36.                 $num = $redis->get($adve_plus); 
  37.                 if($num >10){ 
  38.                     $id = $redis->get($adve_new_key); 
  39.                     // insert to sql; 
  40.                     $mysql_obj->query("update user_online_adve set adve_num=adve_num+$num where id=$id"); 
  41.                     $redis->set($adve_plus,1); 
  42.                 } 
  43.             } 
  44.     } 
  45.     header('HTTP/1.0 301 Moved Permanently'); 
  46.     header('Location: https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8'); 
  47.  
  48.  
  49. /* 
  50.     if(){ 
  51.             $adve_plus = $adve_key.":plus" ; 
  52.             if($redis->exists($adve_plus)){ 
  53.                 $redis->incr($adve_plus); 
  54.             }else{ 
  55.                 $redis->set($adve_plus,1);   
  56.             } 
  57.             echo $redis->get($adve_plus); 
  58.     } 
  59.  
  60.     foreach ($list as $key => $value) { 
  61.             $url_hash = md5($value['adve_url']); 
  62.             $id = $value['id']; 
  63.             $adve_num = $value['adve_num']; 
  64.             $adve_plus = $adve_key.":plus" ; 
  65.             if($redis->exists($adve_plus)){ 
  66.                 $redis->incr($adve_plus); 
  67.             }else{ 
  68.                 $redis->set($adve_plus,1);   
  69.             } 
  70.             echo $redis->get($adve_plus); 
  71.             //if($redis->) 
  72.             //$redis->hmset($adve_key, array('id' =>$id, 'adve_num'=>$adve_num)); 
  73.             //print_r($redis->hmget("adve:$url_hash", array('adve_num'))); 
  74.     } 
  75.  
  76.  
  77.         print_r($list); 
  78. */ 

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 久久9色 | 综合在线一区 | 99在线啪 | 日日噜噜噜夜夜狠狠久久蜜桃 | 久久久一区二区精品 | 久久精品国产精品亚洲 | 久久激情免费视频 | 成人在线精品视频 | 日韩中文字幕三区 | 视频国产一区二区 | 91短视频在线观看 | 日本一区二区不卡在线观看 | 日韩精品 | 毛片在线免费观看完整版 | 欧美成人做爰高潮片免费视频 | 黄色毛片视频在线观看 | 热@国产 | 成人福利视频导航 | 99国产精品自拍 | av免费在线观看国产 | 久久国产精品久久精品国产演员表 | 羞羞答答视频 | 日韩精品中文字幕一区二区 | 久久久久久久久久美女 | 久久精品国产久精国产 | 天天色宗合 | 国产一区二区精品在线观看 | 久久狠狠高潮亚洲精品 | 特黄一区二区三区 | 欧美国产一区二区三区 | 女人裸体让男人桶全过程 | 免费看欧美一级特黄a大片 久久免费视频一区二区三区 | 免费视频www在线观看 | 国产精品久久久久久久久岛 | 久久精品国产99国产精品亚洲 | av在线等 | 双性帝王调教跪撅打屁股 | 欧美成人精品一级 | 国产精品色综合 | 精品偷拍久久 | 精品成人免费一区二区在线播放 |