PHP中Memcache操作类使用方法
- <?php
-
-
-
-
- class Yc_Memcache{
- private $memcache=null;
-
- public function __construct(){
- }
-
-
-
-
-
-
-
- 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;
- }
- }
-
-
-
-
-
-
-
-
- public function set($key,$var,$flag=0,$expire=10){
-
- $f=@memcache_set($this->memcache,$key,$var,$flag,$expire);
- if(emptyempty($f)){
- return FALSE;
- }else{
- return TRUE;
- }
- }
-
-
-
-
-
-
-
-
-
- public function get($key,$flags=0){
- $val=@memcache_get($this->memcache,$key,$flags);
- return $val;
- }
-
-
-
-
-
-
- public function delete($key,$timeout=1){
- $flag=@memcache_delete($this->memcache,$key,$timeout);
- return $flag;
- }
-
-
-
-
- public function flush(){
- memcache_flush($this->memcache);
- }
-
-
-
-
- public function close(){
- memcache_close($this->memcache);
- }
-
-
-
-
-
-
-
-
- public function replace($key,$var,$flag=0,$expire=1){
- $f=memcache_replace($this->memcache,$key,$var,$flag,$expire);
- return $f;
- }
-
-
-
-
-
-
- public function setCompressThreshold($threshold,$min_saveings=0.2){
- $f=@memcache_set_compress_threshold($this->memcache,$threshold,$min_saveings);
- return $f;
- }
-
-
-
-
-
-
- public function getServerStatus($host,$port=11211){
- $re=memcache_get_server_status($this->memcache,$host,$port);
- return $re;
- }
-
-
-
-
-
-
-
- public function getExtendedStats($type='',$slabid=0,$limit=100){
- $re=memcache_get_extended_stats($this->memcache,$type,$slabid,$limit);
- return $re;
- }
- }
-
-
- $mem=new Yc_Memcache();
-
- $f=$mem->connect('125.64.41.138',12000);
- var_dump($f);
- if($f){
-
- $mem->set('key','hello',0,30);
-
-
-
-
- echo $mem->getServerStatus('127.0.0.1',12000);
- echo $mem->get('key');
- echo '<pre>';
- print_r($mem->getExtendedStats());
- }
-
- ?>
|