The example in this article describes how PHP uses Redis to implement statistical caching of MySQL pressure. Share to everyone for your reference, specific as follows:
<?php header ("Content-type:text/html;charset=utf-8");
Include ' lib/mysql.class.php ';
$mysql _obj = Mysql::getconn ();
Redis $redis = new Redis ();
$redis->pconnect (' 127.0.0.1 ', 6379);
if (Isset ($_server[' http_referer ')) {$url _MD5 = MD5 ($_server[' http_referer ']);
} $adve _key = ' adve ';
$adve _key_exists = ' adve_exists ';
if (! $redis->exists ($adve _key_exists)) {$list = $mysql _obj->fetch_array ("SELECT * from User_online_adve");
if ($list) {foreach ($list as $key => $value) {$url _hash = MD5 ($value [' Adve_url ']);
$adve _hash_key = $adve _key. ":" $url _hash;
$id = $value [' id '];
$redis->set ($adve _hash_key, $id);
$redis->set ($adve _key_exists,true);
$redis->hmset ($adve _hash_key, array (' ID ' => $id));
Print_r ($redis->get ($adve _hash_key));
}} $adve _new_key = $adve _key. ': '. $url _md5; if ($redis->exists ($adve _new_key)) {$adve _plus = $adve _new_key. ":p LUs" ;
if (! $redis->exists ($adve _plus)) {$redis->set ($adve _plus,1);
}else{$redis->incr ($adve _plus);
$num = $redis->get ($adve _plus);
if ($num >10) {$id = $redis->get ($adve _new_key);
Insert to SQL;
$mysql _obj->query ("Update user_online_adve set adve_num=adve_num+ $num where id= $id");
$redis->set ($adve _plus,1);
} header (' http/1.0 moved Permanently ');
Header (' location:https://itunes.apple.com/cn/app/san-guo-zhi15-ba-wangno-da-lu/id694974270?mt=8 ');
/* if () {$adve _plus = $adve _key. ":p LUs";
if ($redis->exists ($adve _plus)) {$redis->incr ($adve _plus);
}else{$redis->set ($adve _plus,1);
echo $redis->get ($adve _plus);
foreach ($list as $key => $value) {$url _hash = MD5 ($value [' Adve_url ']);
$id = $value [' id '];
$adve _num = $value [' Adve_num ']; $adve _plus = $adve _key. ":p LUs";
if ($redis->exists ($adve _plus)) {$redis->incr ($adve _plus);
}else{$redis->set ($adve _plus,1);
echo $redis->get ($adve _plus);
if ($redis->)//$redis->hmset ($adve _key, array (' ID ' => $id, ' adve_num ' => $adve _num));
Print_r ($redis->hmget ("Adve: $url _hash", Array (' Adve_num '));
} print_r ($list);
*/
I hope this article will help you with your PHP programming.