Redis applied to php, complete case of connecting to mysql

WBOY
Release: 2016-07-25 08:46:26
Original
1066 people have browsed it
  1. header("Content-type:text/html;charset=utf-8");
  2. error_reporting(0);
  3. $redis=new Redis();
  4. $redis->connect('localhost',6379);
  5. if($redis->exists("blog")){
  6. $b=$redis->get("blog");
  7. $rs=unserialize($b);
  8. foreach($rs as $res){
  9. echo $res['title']."
    ";
  10. }
  11. }
  12. else{
  13. $conn= mysql_connect("localhost","root","root");
  14. mysql_select_db("test");
  15. mysql_query("set names utf8");
  16. $sql="select * from blog";
  17. $result=mysql_query($sql);
  18. $rss=array();
  19. while($rs=mysql_fetch_assoc($result)){
  20. $rss[]=$rs;
  21. $redis->set("blog", serialize($rss));
  22. $b=$redis->get("blog");
  23. $rs=unserialize($b);
  24. foreach($rs as $res){
  25. echo $res['title']."
    ";
  26. }
  27. }
  28. }
复制代码

应用于, Redis, mysql
本主题由 小贝 于 2015-11-12 08:43 移动


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!