|
本文实例讲述了PHP中Memcache操作类及用法。分享给大家供大家参考。具体分析如下:
代码如下:public function __construct(){
}
/**
- 连接数据库
-
- @param mixed $host
- @param mixed $port
- @param mixed $timeout
*/
public function connect($host,$port=11211,$timeout=1){
if(!function_exists(memcache_connect)){ return FALSE;}
$this->memcache=@memcache_connect($host,$port,$timeout);
if(emptyempty($this->memcache)){
return FALSE;
}else{
return TRUE;
}
}
/**
- 存放值
-
- @param mixed $key
- @param mixed $var
- @param mixed $flag 默认为0不压缩 压缩状态填写:MEMCACHE_COMPRESSED
- @param mixed $expire 默认缓存时间(单位秒)
*/
public function set($key,$var,$flag=0,$expire=10){
$f=@memcache_set($this->memcache,$key,$flag,$expire);
if(emptyempty($f)){
return FALSE;
}else{
return TRUE;
}
}
/**
/***测试区域****/
$mem=new Yc_Memcache();
$f=$mem->connect('125.64.41.138',12000);
var_dump($f);
if($f){
// $mem->setCompressThreshold(2000,0.2);
$mem->set('key','hello',30);
// var_dump($mem->delete('key1'));
// $mem->flush();
// var_dump($mem->replace('hao','d'));
// echo $mem->get('key');
echo $mem->getServerStatus('127.0.0.1',12000);
echo $mem->get('key');
echo ' ';
print_r($mem->getExtendedStats());
}
?>
希望本文所述对大家的PHP程序设计有所帮助。 (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|