memcache存储mysql select结果

<?php

$mem=new Memcache;

$mem->connect("localhost",11211);

$sql="select * from uc_members";

$key=md5($sql);

$data=$mem->get($key);

if(!$data){

 

$mysqli=new mysqli("localhost","root","","ucenter");

$result=$mysqli->query($sql);

$data=array();

while ($row=$result->Fetch_assoc()) {

$data[]=$row;

}

$result->free();

$mysqli->close();

$mem->set($key,$data,MEMCACHE_COMPRESSED,3600);

echo $sql;

}

echo '<pre>';

print_r($data);

echo '</pre>';

$mem->close();

?>

相关推荐