Redis应用于php,连接mysql的完整案例

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

<?php
                header("Content-type:text/html;charset=utf-8");
                error_reporting(0);
                $redis=new Redis();
                $redis->connect('localhost',6379);
                if($redis->exists("blog")){
                $b=$redis->get("blog");
                $rs=unserialize($b);
                     foreach($rs as $res){
                        echo $res['title']."<br/>";
                }
                 }
                 else{  
                $conn=  mysql_connect("localhost","root","root");
                mysql_select_db("test");
                mysql_query("set names utf8");
                $sql="select * from blog";
                $result=mysql_query($sql);
                $rss=array();
                while($rs=mysql_fetch_assoc($result)){
                $rss[]=$rs;
                $redis->set("blog", serialize($rss));
                $b=$redis->get("blog");
                $rs=unserialize($b);
                      foreach($rs as $res){
                          echo $res['title']."<br/>";
                }
                }
                 }