memcache缓存

<?php
    phpinfo();
    header("Content-type: text/html; charset=utf-8");
    $db = new mysqli("localhost","root","","ceshi");
    $mem = new Memcache;
    $mflag = $mem->connect("localhost", 11211);
    //var_dump($db);
    $sql = "select * from student";
    $a = query_memcache($sql);
    //var_dump($a);
    function query_memcache($sql,$type=''){
          global $mem;
          global $db;
          $key = md5($sql);
          if(!($value = $mem->get($key))){
           $result = $db->query($sql);
           while($reattr = $result->fetch_assoc()){
                 $attr[] = $reattr;
           }
           $value = $attr;
           
          
           $mem->set($key,$value,0,time()+15);      15秒刷新缓存一次

//set(key,value,过期时间/单位秒); } return $value; } ?>
原文地址:https://www.cnblogs.com/zhengleilei/p/9401120.html