<?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/>"; } } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8980.html