本文整理汇总了PHP中Memcache::increment方法的典型用法代码示例。如果您正苦于以下问题:PHP Memcache::increment方法的具体用法?PHP Memcache::increment怎么用?PHP Memcache::increment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Memcache
的用法示例。
在下文中一共展示了Memcache::increment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: increment
/**
* Increment cache item with given key
*
* @param string $key
* @return integer|false
*/
public function increment($key)
{
if (empty($key)) {
throw new InvalidArgumentException("\$key is empty");
}
return $this->memcache->increment($key);
}
示例2: increment
public function increment($key, $value)
{
try {
return $this->instance->increment($key, $value);
} catch (BaseException $e) {
return null;
}
}
示例3: increment
/**
* Increment the value of the given key
*
* @param string $key
* @return boolean
*/
public function increment($key)
{
if (!$this->hasMemcache) {
return false;
}
$this->memcache->increment($key);
return true;
}
示例4: inc
/**
* {@inheritdoc}
*/
public function inc($name, $delta = 1)
{
if (!$this->has($name)) {
$this->forever($name, $delta);
return $delta;
}
return $this->driver->increment($name, $delta);
}
示例5: increment
/**
* @inheritdoc
*/
public function increment($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->increment($hash, $offset);
}
示例6: get_memcache
/**
* Get global handle for memcache access
*
* @return object Memcache
*/
public function get_memcache()
{
if (!isset($this->memcache)) {
// no memcache support in PHP
if (!class_exists('Memcache')) {
$this->memcache = false;
return false;
}
$this->memcache = new Memcache();
$this->mc_available = 0;
// add all configured hosts to pool
$pconnect = $this->config->get('memcache_pconnect', true);
foreach ($this->config->get('memcache_hosts', array()) as $host) {
if (substr($host, 0, 7) != 'unix://') {
list($host, $port) = explode(':', $host);
if (!$port) {
$port = 11211;
}
} else {
$port = 0;
}
$this->mc_available += intval($this->memcache->addServer($host, $port, $pconnect, 1, 1, 15, false, array($this, 'memcache_failure')));
}
// test connection and failover (will result in $this->mc_available == 0 on complete failure)
$this->memcache->increment('__CONNECTIONTEST__', 1);
// NOP if key doesn't exist
if (!$this->mc_available) {
$this->memcache = false;
}
}
return $this->memcache;
}
示例7: increment
/**
* Increments the value of an integer cached key
*
* @param string $key Identifier for the data
* @param integer $offset How much to increment
* @return New incremented value, false otherwise
* @throws CacheException when you try to increment with compress = true
*/
public function increment($key, $offset = 1)
{
if ($this->settings['compress']) {
throw new CacheException(__d('cake_dev', 'Method increment() not implemented for compressed cache in %s', __CLASS__));
}
return $this->_Memcache->increment($key, $offset);
}
示例8: cache
function cache($op, $key, $val = '', $expiry = 604800)
{
static $memcache = false;
if ($memcache === false) {
$memcache = new Memcache();
$memcache->connect('localhost', 11211) or die('Fatal error - could not connect to Memcache');
}
$retval = true;
// Prefix the key to avoid collisions with other apps
$key = 'twitapps_' . $key;
switch ($op) {
case 'set':
$memcache->set($key, $val, false, $expiry) or die('Fatal error - could not store ' . htmlentities($key) . ' in Memcache');
break;
case 'get':
$retval = $memcache->get($key);
break;
case 'inc':
$retval = $memcache->increment($key);
break;
case 'add':
$retval = $memcache->add($key, $val, false, $expiry);
break;
}
return $retval;
}
示例9: increment
/**
* Increments the value of an integer cached key
*
* @param string $key
* Identifier for the data
* @param integer $offset
* How much to increment
* @param integer $duration
* How long to cache the data, in seconds
* @return New incremented value, false otherwise
* @access public
*/
function increment($key, $offset = 1)
{
if ($this->settings['compress']) {
trigger_error(sprintf(__('Method increment() not implemented for compressed cache in %s', true), get_class($this)), E_USER_ERROR);
}
return $this->__Memcache->increment($key, $offset);
}
示例10: inc
function inc($key)
{
$key = str_replace('\\', '/', $key);
if (!$this->memcache->increment($key)) {
$message = sprintf('Memcache::increment() with key "%s" failed', $key);
\ManiaLib\Utils\Logger::error($message);
}
}
示例11: increment
public function increment($key, $value = 1)
{
if (!$this->is_open) {
return false;
}
$key = $this->format_key($key);
return parent::increment($key, $value);
}
示例12: clearCache
/**
* Clears the cache by incrementing the namespace key
*
* @return void
*/
public function clearCache($partition = '')
{
if (!$this->connected) {
return false;
}
// Memcache has a built in increment method
$this->memcache->increment($partition);
}
示例13: increment
public function increment($key, $value = 1)
{
if (!isset($this->memcache)) {
$this->connect();
}
$key = $this->prefix . $key;
return $this->memcache->increment($key, $value);
}
示例14: incrementCachedVal
protected function incrementCachedVal($cacheKey)
{
if (self::$memcache) {
if ($this->cachePrefix) {
$cacheKey = $this->cachePrefix . "-" . $cacheKey;
}
return self::$memcache->increment($cacheKey);
}
return False;
}
示例15: increment
/**
* 递增
* 与原始increment方法区别的是若memcache不存指定KEY时返回false,这个会自动递增
*
* @param string $key
* @param int $offset
* @param int $lifetime 当递减失则时当作set使用
*/
public function increment($key, $offset = 1, $lifetime = 60)
{
if ($this->_memcache->increment($this->prefix . $key, $offset)) {
return true;
} elseif (null === $this->get($key) && $this->set($key, $offset, $lifetime)) {
return true;
} else {
return false;
}
}