Exemplo n.º 1
0
 public function decrement($key, $value)
 {
     try {
         return $this->instance->decrement($key, $value);
     } catch (BaseException $e) {
         return null;
     }
 }
Exemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function decrement($key, $offset = 1, $expire = 0, $create = true)
 {
     $hash = $this->prepareKey($key);
     if ($this->exists($key) === false) {
         if ($create === false) {
             return false;
         }
         $this->storage->add($hash, 0, MEMCACHE_COMPRESSED, $expire);
     }
     return $this->storage->decrement($hash, $offset);
 }
Exemplo n.º 3
0
 /**
  * Decrement cache item with given key
  *
  * @param string $key
  * @return integer|false
  */
 public function decrement($key)
 {
     if (empty($key)) {
         throw new InvalidArgumentException("\$key is empty");
     }
     return $this->memcache->decrement($key);
 }
 /**
  * Decrements the value of an integer cached key
  *
  * @param string $key
  *        	Identifier for the data
  * @param integer $offset
  *        	How much to substract
  * @param integer $duration
  *        	How long to cache the data, in seconds
  * @return New decremented value, false otherwise
  * @access public
  */
 function decrement($key, $offset = 1)
 {
     if ($this->settings['compress']) {
         trigger_error(sprintf(__('Method decrement() not implemented for compressed cache in %s', true), get_class($this)), E_USER_ERROR);
     }
     return $this->__Memcache->decrement($key, $offset);
 }
Exemplo n.º 5
0
 /**
  * Decrements the value of an integer cached key
  *
  * @param string $key Identifier for the data
  * @param integer $offset How much to subtract
  * @return New decremented value, false otherwise
  * @throws CacheException when you try to decrement with compress = true
  */
 public function decrement($key, $offset = 1)
 {
     if ($this->settings['compress']) {
         throw new CacheException(__d('cake_dev', 'Method %s not implemented for compressed cache in %s', 'decrement()', __CLASS__));
     }
     return $this->_Memcache->decrement($key, $offset);
 }
Exemplo n.º 6
0
 public function decrement($key, $value = 1)
 {
     if (!$this->is_open) {
         return false;
     }
     $key = $this->format_key($key);
     return parent::decrement($key, $value);
 }
Exemplo n.º 7
0
 public function decrement($key, $value = 1)
 {
     if (!isset($this->memcache)) {
         $this->connect();
     }
     $key = $this->prefix . $key;
     return $this->memcache->decrement($key, $value);
 }
Exemplo n.º 8
0
 /**
  * 递减
  * 与原始decrement方法区别的是若memcache不存指定KEY时返回false,这个会自动递减
  *
  * @param string $key
  * @param int $offset
  * @param int $lifetime 当递减失则时当作set使用
  */
 public function decrement($key, $offset = 1, $lifetime = 60)
 {
     if ($this->_memcache->decrement($this->prefix . $key, $offset)) {
         return true;
     } elseif ($this->get($key) === null && $this->set($key, $offset, $lifetime)) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 9
0
 /**
  * 递减
  * @param string $key   键名
  * @param int $step     递减步长
  * @return int|false    递减后的值,失败返回false
  */
 public function decr($key, $step = 1)
 {
     if (!is_int($step)) {
         return false;
     }
     try {
         $value = $this->handler->get($key);
         if ($value === false) {
             if ($this->handler->set($key, $value = -$step, 0)) {
                 return $value;
             }
         } else {
             //memcache会将数字存储为字符串
             if (!is_numeric($value)) {
                 return false;
             }
             $timeValue = self::getValue($this->handler->get(self::timeKey($key)));
             //未设置过期时间或未过期
             if ($timeValue === false || isset($timeValue['expire_time']) && $timeValue['expire_time'] > time()) {
                 //memcache 新的元素的值不会小于0
                 if ($value < 0 || $step > 0 && $value < $step) {
                     if ($this->handler->set($key, $value -= $step, 0)) {
                         return $value;
                     }
                 } else {
                     if ($step > 0) {
                         $ret = $this->handler->decrement($key, $step);
                         return $ret;
                     } else {
                         return $this->handler->increment($key, -$step);
                     }
                 }
             }
             //已过期,重新设置
             if ($this->handler->set($key, $value = $step, 0)) {
                 return $value;
             }
         }
         return false;
     } catch (Exception $ex) {
         self::exception($ex);
         //连接状态置为false
         $this->isConnected = false;
     }
     return false;
 }
Exemplo n.º 10
0
 /**
  *
  * @param string $key
  * @param int $value
  * @return number
  * @todo 多备份实例上无原子操作
  */
 public function decrease($key, $value = 1)
 {
     if ($this->backupInstance) {
         $backupReturn = $this->backupInstance->decrease($key, $value);
     }
     $key = $this->makeRealKey($key);
     $return = parent::decrement($key, $value);
     if ($return === false) {
         $newValue = parent::get($key);
         if (false !== $newValue) {
             $backupValue['data'] = $newValue;
             parent::set($this->getBackupKey($key), $backupValue, MEMCACHE_COMPRESSED, 0);
         }
     }
     return $return;
 }
Exemplo n.º 11
0
 /**
  * {@inheritdoc}
  */
 public function dec($name, $delta = 1)
 {
     return $this->driver->decrement($name, $delta);
 }
Exemplo n.º 12
0
 /**
  * Decrement a cache value
  *
  * @param string $p_sKey The Key
  * @param numeric $p_mDecrement The Decremental Value
  * @return numeric
  */
 function decrement($p_sKey, $p_mDecrement)
 {
     return $this->_handler->decrement($p_sKey, $p_mDecrement);
 }
Exemplo n.º 13
0
 /**
  * Decrements a given value by the step value supplied.
  * Useful for shared counters and other persistent integer based
  * tracking.
  *
  * @param   string    id of cache entry to decrement
  * @param   int       step value to decrement by
  * @return  integer
  * @return  boolean
  */
 public function decrement($id, $step = 1)
 {
     return $this->_memcache->decrement($id, $step);
 }
Exemplo n.º 14
0
/**
 * Decrements the value of an integer cached key
 *
 * @param string $key Identifier for the data
 * @param int $offset How much to subtract
 * @return New decremented value, false otherwise
 * @throws CacheException when you try to decrement with compress = true
 */
	public function decrement($key, $offset = 1) {
		return $this->_Memcached->decrement($key, $offset);
	}
Exemplo n.º 15
0
		ajax_only();

		$peer = intval($_POST['peer']);

		$new = get_new_counts($uid, true);

		$new_peer = $new['peers'][$peer];

		if($new_peer > 0){
			foreach($new['ids'][$peer] as $id){
				$msg = $im->get("message{$uid}_{$id}#4");

				$msg = explode("\t", $msg);
				$msg_data = explode(',', $msg[0]);

				$im->decrement("flags{$uid}_{$id}", 1);
				$im->decrement("flags{$peer}_{$msg_data[3]}", 1);
			}
			$im->set("history_action{$peer}#51", "{$uid},1");

			$queue = new Memcache;
			$queue->connect('127.0.0.1', QUE_PORT);
			$queue->add("queue(notify{$uid})", json_encode(array('type' => 'msg_count', 'cnt' => $new_msg['all'])));

			$dialog_num = $new['unicue']-1;
		}else $dialog_num = $new['unicue'];

		echo json_encode(array('dialog_num' => $dialog_num));

		exit;
	break;
Exemplo n.º 16
0
 /**
  * Decrement the value of an item in the cache.
  *
  * @param  string  $key
  * @param  mixed   $value
  * @return int|bool
  */
 public function decrement($key, $value = 1)
 {
     return $this->memcache->decrement($this->prefix . $key, $value);
 }
Exemplo n.º 17
0
 /**
  * Decrements a given value by the step value supplied.
  * Useful for shared counters and other persistent integer based
  * tracking.
  *
  * @param   string   $id    ID of cache entry to decrement
  * @param   integer  $step  Step value to decrement by [Optional]
  *
  * @return  integer|boolean
  *
  * @uses    System::sanitize_id
  */
 public function decrement($id, $step = 1)
 {
     return $this->_memcache->decrement(System::sanitize_id($this->config('prefix') . $id), $step);
 }
 /**
  * Decrement a key.
  */
 function decrement($key, $value = 1)
 {
     $key = $this->key($key);
     return parent::decrement($key, $value);
 }
Exemplo n.º 19
0
<?php

$key = 'TEST_KEY_INCREMENT_DECREMENT';
$memcache = new Memcache();
$memcache->addServer('127.0.0.1', 11211);
$memcache->delete($key);
var_dump($memcache->increment($key, 1));
var_dump($memcache->get($key));
$memcache->set($key, 0);
var_dump($memcache->increment($key, 1));
$memcache->delete($key);
var_dump($memcache->decrement($key, 1));
var_dump($memcache->get($key));
$memcache->set($key, 0);
var_dump($memcache->decrement($key, 1));
$memcache->delete($key);
Exemplo n.º 20
0
 /**
  * 新增incrementEx方法
  * 支持如下两个变化
  * 1. 如果cacheId不存在,自动重新创建
  * 2. 支持负数和正数,自动根据符号判断
  *
  * @param string $cacheId
  * @param int $value
  * @return int
  */
 public function incrementEx($cacheId, $value = 1)
 {
     //如果cacheId不存在,直接设置
     if (false === parent::get($cacheId)) {
         return parent::set($cacheId, $value);
     }
     //判断value的正负分别处理
     if ($value > 0) {
         return parent::increment($cacheId, $value);
     } else {
         return parent::decrement($cacheId, -$value);
     }
 }
Exemplo n.º 21
0
 /**
  * @see Temporary_cache_driver::dec()
  */
 public function dec($id, $realm = COT_DEFAULT_REALM, $value = 1)
 {
     $id = self::createKey($id);
     return $this->memcache->decrement($realm . '/' . $id, $value);
 }
Exemplo n.º 22
0
function memcache_decrement($m, $key, $value = 1)
{
    return Memcache::decrement($m, $key, $value);
}
Exemplo n.º 23
0
 /**
  * {@inheritdoc}
  */
 public function decrement($name, $delta = 1)
 {
     return $this->service->decrement($name, $delta);
 }
Exemplo n.º 24
0
 public function decrement($id)
 {
     return false !== @$this->memcache->decrement($id);
 }
Exemplo n.º 25
0
 /**
  * @inheritdoc
  */
 public function decrement($name, $offset = 1)
 {
     return $this->driver->decrement($name, $offset);
 }
Exemplo n.º 26
0
/**
 * Decrements a cached item's value. The value must be a int, float or string
 * representing an integer e.g. 5, 5.0 or "5" or the call with fail.
 *
 * @param Memcache $memcache_obj The cache instance to decrement the value in.
 *
 * @param string $key The key associated with the value to decrement.
 *
 * @param int $value The amount to decrement the value.
 *
 * @return mixed On success, the new value of the item is returned. On
 *               failure, false is returned.
 */
function memcache_decrement($memcache_obj, $key, $value = 1)
{
    return $memcache_obj->decrement($key, $value);
}
Exemplo n.º 27
0
 /**
  * 当k存在时,对k值进行减法,默认减1
  * @注意:当k不存在时,不会创建该k
  * @param number $num
  * @return int 新的值(不会小于0)
  */
 public function decrK($num = 1)
 {
     return $this->mc->decrement($this->k, $num);
 }
Exemplo n.º 28
0
 /**
  * {@inheritDoc}
  *
  * @see http://www.php.net/manual/en/memcache.decrement.php
  */
 protected function _decrement($key, $value)
 {
     return $this->_connection->decrement($key, $value);
 }
Exemplo n.º 29
0
 /**
  * Decrements a given value by one
  *
  * @param String $key The key for the value
  * @return \r8\Cache\Memcache Returns a self reference
  */
 public function decrement($key)
 {
     $this->connect();
     $this->link->decrement($key);
     return $this;
 }
Exemplo n.º 30
0
 /**
  * {@inheritdoc}
  */
 public function dec($key, $step = 1)
 {
     $this->setConnected();
     return $this->memcache->decrement($this->getKey($key), $step);
 }