本文整理汇总了PHP中apcu_dec函数的典型用法代码示例。如果您正苦于以下问题:PHP apcu_dec函数的具体用法?PHP apcu_dec怎么用?PHP apcu_dec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了apcu_dec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decr
public function decr($key, $value = 1)
{
/**
* @todo When we only support php 7 or higher remove this hack
*
* https://github.com/krakjoe/apcu/issues/166
*/
if (apcu_exists($key . self::KEY_SUFFIX)) {
return apcu_dec($key . self::KEY_SUFFIX, $value);
} else {
return apcu_set($key . self::KEY_SUFFIX, -$value);
}
}
示例2: testApcu
public function testApcu()
{
$key = __CLASS__;
apcu_delete($key);
$this->assertFalse(apcu_exists($key));
$this->assertTrue(apcu_add($key, 123));
$this->assertTrue(apcu_exists($key));
$this->assertSame(array($key => -1), apcu_add(array($key => 123)));
$this->assertSame(123, apcu_fetch($key));
$this->assertTrue(apcu_store($key, 124));
$this->assertSame(124, apcu_fetch($key));
$this->assertSame(125, apcu_inc($key));
$this->assertSame(124, apcu_dec($key));
$this->assertTrue(apcu_cas($key, 124, 123));
$this->assertFalse(apcu_cas($key, 124, 123));
$this->assertTrue(apcu_delete($key));
$this->assertFalse(apcu_delete($key));
$this->assertArrayHasKey('cache_list', apcu_cache_info());
}
示例3: decrement
/**
* 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 \apcu_dec($id, $step);
}
示例4: decrement
/**
* {@inheritdoc}
*
* @return \Orno\Cache\Adapter\Apc
*/
public function decrement($key, $offset = 1)
{
if ($this->apcu) {
apcu_dec($key, $offset);
} else {
apc_dec($key, $offset);
}
return $this;
}
示例5: decrement
/**
* 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)
{
if (apcu_exists($id)) {
return apcu_dec($id, $step);
} else {
return FALSE;
}
}
示例6: internalDecrementItem
/**
* Internal method to decrement an item.
*
* @param string $normalizedKey
* @param int $value
* @return int|bool The new value on success, false on failure
* @throws Exception\ExceptionInterface
*/
protected function internalDecrementItem(&$normalizedKey, &$value)
{
$options = $this->getOptions();
$namespace = $options->getNamespace();
$prefix = $namespace === '' ? '' : $namespace . $options->getNamespaceSeparator();
$internalKey = $prefix . $normalizedKey;
$value = (int) $value;
$newValue = apcu_dec($internalKey, $value);
// initial value
if ($newValue === false) {
$ttl = $options->getTtl();
$newValue = -$value;
if (!apcu_add($internalKey, $newValue, $ttl)) {
throw new Exception\RuntimeException("apcu_add('{$internalKey}', {$newValue}, {$ttl}) failed");
}
}
return $newValue;
}
示例7: decrement
/**
* Decrement the value of an item in the cache.
*
* @param string $key
* @param mixed $value
* @return int|bool
*/
public function decrement($key, $value)
{
return $this->apcu ? apcu_dec($key, $value) : apc_dec($key, $value);
}
示例8: decrement
public function decrement($key)
{
return $this->apcu ? apcu_dec($key) : apc_dec($key);
}
示例9: dec
/**
* Decrease a stored number
*
* @param string $key
* @param int $step
* @return int | bool
*/
public function dec($key, $step = 1)
{
return apcu_dec($this->getPrefix() . $key, $step);
}
示例10: cache_Dec
function cache_Dec($key, $step = 1)
{
global $CACHE_STORE_COUNT;
$CACHE_STORE_COUNT++;
return apcu_dec($key, $step);
}
示例11: dec
/**
* Decreases a value from the shared memory storage.
*
* Decreases a value from the shared memory storage. Unlike a plain
* set($key, get($key)-$step) combination, this function also implicitly
* performs locking.
*
* @param string $key Name of key to decrease.
* @param int $step Value to decrease the key by.
*
* @return int The new value.
*/
public function dec($key, $step = 1)
{
$newValue = apcu_dec($this->persistentId . 'd ' . $key, (int) $step, $success);
if (!$success) {
throw new SHM\InvalidArgumentException('Unable to decrease the value. Are you sure the value is int?', 103);
}
return $newValue;
}
示例12: decrement
/**
* Decrease the value of a stored integer
*
* @param string $key Unique item identifier
* @param int $value The ammount by which to decrement
*
* @return mixed Item's new value on success, otherwise false
*/
public function decrement($key, $value = 1)
{
// Check for key existance first as a temporary workaround
// for this bug: https://github.com/krakjoe/apcu/issues/183
if (apcu_exists($this->prefix($key))) {
return apcu_dec($this->prefix($key), $value);
}
return false;
}
示例13: dec
public function dec($key, $step = 1)
{
$value = apcu_dec($key, $step, $success);
return $success ? $value : false;
}
示例14: decrementValue
/**
* {@inheritdoc}
*/
protected function decrementValue($key, $value)
{
$val = apcu_dec($key, $value, $success);
return $success ? (int) $val : false;
}
示例15: dec
public function dec(string $key, int $step) : bool
{
return apcu_dec($key, $step);
}