replace() public method

Replace the value of a key.
See also: Memcache::replace()
public replace ( string $key, string $var, $expire ) : boolean
$key string The key.
$var string The data to store.
return boolean True on success, false if key doesn't exist.
示例#1
0
文件: Memcache.php 项目: horde/horde
 /**
  */
 public function write($id, $session_data)
 {
     if (!empty($this->_params['track'])) {
         // Do a replace - the only time it should fail is if we are
         // writing a session for the first time.  If that is the case,
         // update the session tracker.
         $res = $this->_memcache->replace($id, $session_data);
         $track = !$res;
     } else {
         $res = $track = false;
     }
     if (!$res && !$this->_memcache->set($id, $session_data)) {
         return false;
     }
     if ($track) {
         $this->_memcache->lock($this->_trackID);
         $ids = $this->_memcache->get($this->_trackID);
         if ($ids === false) {
             $ids = array();
         }
         $ids[$id] = time();
         $this->_memcache->set($this->_trackID, $ids);
         $this->_memcache->unlock($this->_trackID);
     }
     return true;
 }
示例#2
0
文件: Memcache.php 项目: horde/horde
 /**
  */
 protected function _set($key, $val, $opts)
 {
     return empty($opts['replace']) ? $this->_memcache->set($key, $val, isset($opts['expire']) ? $opts['expire'] : 0) : $this->_memcache->replace($key, $val, isset($opts['expire']) ? $opts['expire'] : 0);
 }