{"id":921,"date":"2021-03-10T17:43:56","date_gmt":"2021-03-10T09:43:56","guid":{"rendered":"http:\/\/www.tra56.com\/?p=921"},"modified":"2021-03-10T17:43:56","modified_gmt":"2021-03-10T09:43:56","slug":"921","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/921.html","title":{"rendered":"PHP\u4f7f\u7528redis\u5b9e\u73b0\u7edf\u8ba1\u7f13\u5b58mysql\u538b\u529b\u7684\u65b9\u6cd5"},"content":{"rendered":"
\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86PHP\u4f7f\u7528redis\u5b9e\u73b0\u7edf\u8ba1\u7f13\u5b58mysql\u538b\u529b\u7684\u65b9\u6cd5,\u6d89\u53caPHP\u64cd\u4f5cMySQL\u6570\u636e\u5e93\u53ca\u4f7f\u7528Redis\u7edf\u8ba1\u7684\u76f8\u5173\u6280\u5de7<\/p>\n
<?php\r\n header("Content-Type:text\/html;charset=utf-8");\r\n include 'lib\/mysql.class.php';\r\n $mysql_obj = mysql::getConn();\r\n \/\/redis \r\n $redis = new Redis();\r\n $redis->pconnect('127.0.0.1', 6379);\r\n if(isset($_SERVER['HTTP_REFERER'])){\r\n $url_md5 = md5($_SERVER['HTTP_REFERER']);\r\n }\r\n $adve_key = 'adve'; \r\n $adve_key_exists = 'adve_exists';\r\n if(!$redis->exists($adve_key_exists)){\r\n $list = $mysql_obj->fetch_array("select * from user_online_adve");\r\n if($list){\r\n foreach ($list as $key => $value) {\r\n $url_hash = md5($value['adve_url']);\r\n $adve_hash_key = $adve_key.":".$url_hash;\r\n $id = $value['id'];\r\n $redis->set($adve_hash_key,$id);\r\n $redis->set($adve_key_exists,true);\r\n \/\/$redis->hmset($adve_hash_key, array('id' =>$id));\r\n \/\/print_r($redis->get($adve_hash_key));\r\n }\r\n }\r\n }\r\n $adve_new_key = $adve_key.':'.$url_md5;\r\n if($redis->exists($adve_new_key)){\r\n $adve_plus = $adve_new_key.":plus" ;\r\n if(!$redis->exists($adve_plus)){\r\n $redis->set($adve_plus,1); \r\n }else{\r\n $redis->incr($adve_plus);\r\n $num = $redis->get($adve_plus);\r\n if($num >10){\r\n $id = $redis->get($adve_new_key);\r\n \/\/ insert to sql;\r\n $mysql_obj->query("update user_online_adve set adve_num=adve_num+$num where id=$id");\r\n $redis->set($adve_plus,1);\r\n }\r\n }\r\n }\r\n header('HTTP\/1.0 301 Moved Permanently');\r\n header('Location: https:\/\/itunes.apple.com\/cn\/app\/san-guo-zhi15-ba-wangno-da-lu\/id694974270?mt=8');\r\n\/*\r\n if(){\r\n $adve_plus = $adve_key.":plus" ;\r\n if($redis->exists($adve_plus)){\r\n $redis->incr($adve_plus);\r\n }else{\r\n $redis->set($adve_plus,1); \r\n }\r\n echo $redis->get($adve_plus);\r\n }\r\n foreach ($list as $key => $value) {\r\n $url_hash = md5($value['adve_url']);\r\n $id = $value['id'];\r\n $adve_num = $value['adve_num'];\r\n $adve_plus = $adve_key.":plus" ;\r\n if($redis->exists($adve_plus)){\r\n $redis->incr($adve_plus);\r\n }else{\r\n $redis->set($adve_plus,1); \r\n }\r\n echo $redis->get($adve_plus);\r\n \/\/if($redis->)\r\n \/\/$redis->hmset($adve_key, array('id' =>$id, 'adve_num'=>$adve_num));\r\n \/\/print_r($redis->hmget("adve:$url_hash", array('adve_num')));\r\n }\r\n print_r($list);\r\n*\/<\/pre>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86PHP\u4f7f\u7528redis\u5b9e\u73b0\u7edf\u8ba1\u7f13\u5b58mysql\u538b\u529b\u7684\u65b9\u6cd5,\u6d89\u53caPHP\u64cd\u4f5cMySQL\u6570\u636e\u5e93\u53ca\u4f7f\u7528R […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[26,72,70],"class_list":["post-921","post","type-post","status-publish","format-standard","hentry","category-php","tag-php"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/921"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=921"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/921\/revisions"}],"predecessor-version":[{"id":922,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/921\/revisions\/922"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}