Heim > php教程 > php手册 > php memcache类

php memcache类

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Freigeben: 2016-06-06 20:07:55
Original
1602 Leute haben es durchsucht

?php/** 2012-12-04 14:54* @author 孤独求学人*/class php_memcache{protected $handle = null;protected $mem = null;private $host = "";private $port = "";private $timeout = 0;private $pconnect = false;public function __construct($host = '127.0

<?php /*
* 2012-12-04 14:54
* @author 孤独求学人
*/
class php_memcache{
protected $handle  = null;
protected $mem  = null;
private $host   = "";
private $port   = "";
private $timeout  = 0;
private $pconnect = false;
public function __construct($host = '127.0.0.1',$port='11211',$timeout=0,$pconnect=false){
  $this->host = $host;
  $this->port = $port;
  $this->timeout = $timeout;
  $this->pconnect = $pconnect;
  $this->mem     = new Memcache();
}
public function connect(){
  if(!is_resource($this->handle)) {
   if($this->pconnect == false){
    if(empty($this->host)){
     return false;
    }
    if(empty($this->port)){
     return false;
    }
    $handle = $this->mem->connect($this->host,$this->port);
    if(!$handle){
     return false;
    }else{
     $this->handle = $handle;
    }
   }
  }
  return $this->handle;
}
public function set($key,$val,$flag=false,$expire=0){
  if(!$this->connect()) return false;
  $iFlage = 0;
  if($flag == true){
   $iFlage = MEMCACHE_COMPRESSED;
  }
  return $this->mem->set($key,$val,$iFlage,$expire);
}
public function get($key){
  if(!$this->connect()) return false;
  if (is_array($key)) {
             $dest = array();
             foreach ($key as $subkey) {
              $val = $this->get($subkey);
              if (!($val === false)){
               $dest[$subkey] = $val;
              }
             }
             return $dest;
         } else {
             return $this->mem->get($key);
         }
}
public function replace($key,$val,$flag=false,$expire=0){
  if(!$this->connect()) return false;
     $iFlage = 0;
  if($flag == true){
   $iFlage = MEMCACHE_COMPRESSED;
  }
  return $this->mem->replace($key,$val,$iFlage,$expire);
}
public function delete($key,$time=0){
  if(!$this->connect()) return false;
  return $this->mem->delete($key,$time);
}
public function flush(){
  if(!$this->connect()) return false;
  return $this->mem->flush();
}
public function incr($key,$val=1){
  if(!$this->connect()) return false;
  return $this->mem->increment($key,$val);
}
    public function decr($key,$val=1){
  if(!$this->connect()) return false;
  return $this->mem->decrement($key,$val);
}
public function getVersion(){
  if(!$this->connect()) return false;
  return $this->mem->getVersion();
}
}
?>
Nach dem Login kopieren
Verwandte Etiketten:
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Aktuelle Ausgaben
PHP-Datenerfassung?
Aus 1970-01-01 08:00:00
0
0
0
PHP-Erweiterung intl
Aus 1970-01-01 08:00:00
0
0
0
Wie man PHP gut lernt
Aus 1970-01-01 08:00:00
0
0
0
Mehrere PHP-Versionen
Aus 1970-01-01 08:00:00
0
0
0
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage