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

首頁 > 開發(fā) > PHP > 正文

PHP使用redis實(shí)現(xiàn)統(tǒng)計緩存mysql壓力的方法

2024-05-04 23:40:23
字體:
供稿:網(wǎng)友

這篇文章主要介紹了PHP使用redis實(shí)現(xiàn)統(tǒng)計緩存mysql壓力的方法,涉及PHP操作MySQL數(shù)據(jù)庫及使用Redis統(tǒng)計的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP使用redis實(shí)現(xiàn)統(tǒng)計緩存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. if(isset($_SERVER['HTTP_REFERER'])){ 
  9. $url_md5 = md5($_SERVER['HTTP_REFERER']); 
  10. $adve_key = 'adve';  
  11. $adve_key_exists = 'adve_exists'
  12. if(!$redis->exists($adve_key_exists)){ 
  13. $list = $mysql_obj->fetch_array("select * from user_online_adve"); 
  14. if($list){ 
  15. foreach ($list as $key => $value) { 
  16. $url_hash = md5($value['adve_url']); 
  17. $adve_hash_key = $adve_key.":".$url_hash; 
  18. $id = $value['id']; 
  19. $redis->set($adve_hash_key,$id); 
  20. $redis->set($adve_key_exists,true); 
  21. //$redis->hmset($adve_hash_key, array('id' =>$id)); 
  22. //print_r($redis->get($adve_hash_key)); 
  23. $adve_new_key = $adve_key.':'.$url_md5; 
  24. if($redis->exists($adve_new_key)){ 
  25. $adve_plus = $adve_new_key.":plus" ; 
  26. if(!$redis->exists($adve_plus)){ 
  27. $redis->set($adve_plus,1);  
  28. }else
  29. $redis->incr($adve_plus); 
  30. $num = $redis->get($adve_plus); 
  31. if($num >10){ 
  32. $id = $redis->get($adve_new_key); 
  33. // insert to sql; 
  34. $mysql_obj->query("update user_online_adve set adve_num=adve_num+$num where id=$id"); 
  35. $redis->set($adve_plus,1); 
  36. header('HTTP/1.0 301 Moved Permanently'); 
  37. header('Location: https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8'); 
  38. /* 
  39. if(){ 
  40. $adve_plus = $adve_key.":plus" ; 
  41. if($redis->exists($adve_plus)){ 
  42. $redis->incr($adve_plus); 
  43. }else{ 
  44. $redis->set($adve_plus,1);  
  45. } 
  46. echo $redis->get($adve_plus); 
  47. } 
  48. foreach ($list as $key => $value) { 
  49. $url_hash = md5($value['adve_url']); 
  50. $id = $value['id']; 
  51. $adve_num = $value['adve_num']; 
  52. $adve_plus = $adve_key.":plus" ; 
  53. if($redis->exists($adve_plus)){ 
  54. $redis->incr($adve_plus); 
  55. }else{ 
  56. $redis->set($adve_plus,1);  
  57. } 
  58. echo $redis->get($adve_plus); 
  59. //if($redis->) 
  60. //$redis->hmset($adve_key, array('id' =>$id, 'adve_num'=>$adve_num)); 
  61. //print_r($redis->hmget("adve:$url_hash", array('adve_num'))); 
  62. } 
  63. print_r($list); 
  64. */ 

希望本文所述對大家php程序設(shè)計有所幫助。


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 南木林县| 建水县| 蚌埠市| 喀喇| 安庆市| 沧源| 亳州市| 车险| 临猗县| 耒阳市| 田林县| 凌海市| 东宁县| 杨浦区| 延吉市| 霞浦县| 鄂托克旗| 武强县| 霍山县| 钟山县| 乳源| 塔河县| 英吉沙县| 嘉黎县| 苏尼特右旗| 平利县| 六安市| 始兴县| 开江县| 岚皋县| 松滋市| 北流市| 正阳县| 恩平市| 滦平县| 贵德县| 霍林郭勒市| 富民县| 天镇县| 宿州市| 武鸣县|