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());
}
?>