memcache

<?php

//phpinfo();

$mem = new memcache;

$mem->connect(‘127.0.0.1‘,‘11211‘) or die(‘connect error‘);


$mem->add(‘one‘, array(‘aaa‘,‘bbb‘,‘ccc‘), false , time() + 60*60*24*31 );

$mem->set(‘two‘, ‘zhangguo‘, false, 0);

//echo $mem->getVersion();exit();

$mem->delete(‘two‘, 0);

echo $mem->get(‘two‘);


$mem->set(‘three‘, ‘10‘, false, 0);

$mem->increment(‘three‘, 5);

echo $mem->get(‘three‘);

//$mem->delete(‘keyName‘);

//$mem->flush();

//$mem->add(‘namexxx‘,‘123456‘);

// echo $mem->get(‘names‘);

//$array = array(‘123‘,‘46‘,‘xxx‘,‘zhangdh‘);

//$mem->set(‘keyName‘,$array);

//$mem->delete(‘keyName‘);

//print_r($mem->getStats());

?>



============================

<?php

$mem = new Memcache;

$mem->addServer(‘127.0.0.1‘, ‘11211‘);

//$mem->addServer(‘192.168.1.1‘, ‘11211‘);


$sql = "SELECT `spuSn` FROM dc_item_spu where spuSn!=‘‘ limit 3";

$key = md5($sql);


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

if (empty($data)) {

$conn = mysql_connect(‘localhost:3306‘, ‘root‘, ‘123456‘);

mysql_select_db(‘listing‘, $conn);


//执行MySQL语句

$query = mysql_query($sql);


$data = array();

//提取数据

while ($row = mysql_fetch_array($query)) {

echo $row[‘spuSn‘]."\r\n";

$data[] = $row[‘spuSn‘];

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

echo "从数据库中读取\r\n";

}


print_r($data);


 

//print_r($row);



?>


郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。