国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 數據庫 > Redis > 正文

PHP 利用redis 做統計緩存mysql的壓力

2020-03-17 12:44:03
字體:
來源:轉載
供稿:網友
PHP 利用redis 做統計緩存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. */ 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙江县| 博客| 阳春市| 娄底市| 洱源县| 镇远县| 濉溪县| 古丈县| 犍为县| 边坝县| 星座| 广水市| 拉萨市| 宁明县| 迭部县| 洛扎县| 赣榆县| 浦城县| 阿鲁科尔沁旗| 东乡族自治县| 长垣县| 石家庄市| 南川市| 株洲市| 玛纳斯县| 攀枝花市| 买车| 同德县| 萨嘎县| 九龙城区| 故城县| 城固县| 重庆市| 上栗县| 论坛| 喀喇沁旗| 共和县| 江津市| 陆良县| 舟曲县| 贡山|