当前位置: 首页>>代码示例>>PHP>>正文


PHP memcache_add函数代码示例

本文整理汇总了PHP中memcache_add函数的典型用法代码示例。如果您正苦于以下问题:PHP memcache_add函数的具体用法?PHP memcache_add怎么用?PHP memcache_add使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了memcache_add函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: memcache_safeadd

function memcache_safeadd(&$memcache_obj, $key, $value, $flag, $expire)
{
    if (memcache_add($memcache_obj, $key, $value, $flag, $expire)) {
        return $value == memcache_get($memcache_obj, $key);
    }
    return FALSE;
}
开发者ID:JeremyHutchings,项目名称:OffLog,代码行数:7,代码来源:offLogWorker.php

示例2: pdb_get_data

function pdb_get_data($key, $provider, $arguments = [])
{
    $mc_handler = memcache_pconnect(MC_HOST);
    $value = memcache_get($mc_handler, $key);
    if ($value !== false) {
        return $value;
    } else {
        $locking_key = 'lock_' . $key;
        $locking_value = microtime(true);
        for ($i = 0; $i < MC_LOCK_DELAY * 1000 / MC_SLEEP_TIME + 1; $i++) {
            $lock = memcache_add($mc_handler, $locking_key, $locking_value, 0, MC_LOCK_DELAY);
            if ($lock) {
                $value = call_user_func_array($provider, $arguments);
                memcache_set($mc_handler, $key, $value);
                memcache_delete($mc_handler, $locking_key);
                return $value;
            } else {
                usleep(MC_SLEEP_TIME);
                $value = memcache_get($mc_handler, $key);
                if ($value != false) {
                    return $value;
                }
            }
        }
    }
    return call_user_func_array($provider, $arguments);
}
开发者ID:plFlok,项目名称:vk_test_task,代码行数:27,代码来源:db_cache_proxy.php

示例3: add

 private function add($key, $var, $timeout)
 {
     $this->check();
     if (!memcache_add($this->connection, $key, $var, 0, $timeout)) {
         throw new CacheException("Couldn't add to cache");
     }
 }
开发者ID:jkinner,项目名称:ringside,代码行数:7,代码来源:CacheMemcache.php

示例4: createLock

 private function createLock($key)
 {
     $this->check();
     // the interesting thing is that this could fail if the lock was created in the meantime..
     // but we'll ignore that out of convenience
     @memcache_add($this->connection, $key . '.lock', '', 0, 5);
 }
开发者ID:JamesLinus,项目名称:platform,代码行数:7,代码来源:Google_MemcacheCache.php

示例5: cache_add

function cache_add($key, $data, $expires)
{
    $connection = cache_connect();
    $res = memcache_add($connection, (string) $key, $data, false, (int) $expires);
    memcache_close($connection);
    return $res;
}
开发者ID:smarty-kiki,项目名称:frame,代码行数:7,代码来源:cache.php

示例6: cache_set

function cache_set($key, $value)
{
    if (!cache_connect()) {
        return false;
    }
    $key = $GLOBALS['config']['service']['server'] . '/' . $key;
    $op = memcache_replace(object('memcache'), $key, $value, MEMCACHE_COMPRESSED, 60 * 60);
    if ($op == false) {
        memcache_add(object('memcache'), $key, $value, MEMCACHE_COMPRESSED, 60 * 60);
    }
}
开发者ID:hcopr,项目名称:Hubbub,代码行数:11,代码来源:genlib.php

示例7: SaeMemcacheAdd

function SaeMemcacheAdd($key, $value)
{
    //如果长度超出,则取末尾的234位
    if (strlen($key) > 234) {
        $key = substr($key, -234);
    }
    $mmc = memcache_init();
    if ($mmc == false) {
        return false;
    } else {
        return memcache_add($mmc, $key, $value);
    }
}
开发者ID:ribunkou,项目名称:MyPHP,代码行数:13,代码来源:SaeMemcache.php

示例8: testAddAlreadyThere

 public function testAddAlreadyThere()
 {
     $memcache = new Memcache();
     $request = new MemcacheSetRequest();
     $item = $request->addItem();
     $item->setKey("float");
     $item->setValue("2");
     $item->setFlags(6);
     // float
     $item->setSetPolicy(SetPolicy::ADD);
     $item->setExpirationTime(30);
     $response = new MemcacheSetResponse();
     $response->addSetStatus(SetStatusCode::NOT_STORED);
     $this->apiProxyMock->expectCall('memcache', 'Set', $request, $response);
     $this->assertFalse(memcache_add($memcache, "float", 2.0, null, 30));
     $this->apiProxyMock->verify();
 }
开发者ID:bitcpf,项目名称:djangoage,代码行数:17,代码来源:MemcacheTest.php

示例9: lock_lock

/**
 * Функция взятия блокировки для изменения заказа
 * @param int $orderId идентификатор заказа
 * @param int $wait время ожидания блокировки, если она есть, сек
 * @param int $ttl время жизни блокировки, сек
 * @return bool результат взятия блокировки
 */
function lock_lock($orderId, $wait, $ttl)
{
    $key = sprintf('ordr_%s', $orderId);
    $connection = lock_getconnection();
    $result = memcache_add($connection, $key, 1, false, $ttl);
    if ($result === false) {
        $end = microtime() + $wait * 1000;
        for (; microtime() < $end;) {
            usleep(100000);
            $result = memcache_add($connection, $key, 1, false, $ttl);
            if ($result === true) {
                return true;
            }
        }
        return false;
    } else {
        return true;
    }
}
开发者ID:alxmslwork,项目名称:order,代码行数:26,代码来源:lock.php

示例10: lock

 private function lock()
 {
     if ($this->access === false) {
         $i = 0;
         while (!memcache_add(self::$client, $this->queueName . self::LOCK_KEY, 1, false, $this->expire)) {
             usleep($this->sleepTime);
             @$i++;
             if ($i > $this->retryNum) {
                 //尝试等待N次
                 return false;
                 break;
             }
         }
         return $this->access = true;
     }
     return false;
 }
开发者ID:herrify,项目名称:asyn,代码行数:17,代码来源:memcache.php

示例11: add

 public static function add($key, $value, $expire = 0)
 {
     return \memcache_add(self::$connection, $key, $value, self::$flags, $expire);
 }
开发者ID:Acidburn0zzz,项目名称:OEM,代码行数:4,代码来源:Memcache.php

示例12: sessionRead

 /**
  * Reads data from doctrine tables and return its content
  * @param string $id
  * @throws AppKitDoctrineSessionStorageException
  */
 public function sessionRead($id)
 {
     $session = memcache_get($this->memcache, $this->prefix . $this->getParameter('session_name') . ":" . $id);
     if (!$session) {
         memcache_add($this->memcache, $this->prefix . $this->getParameter('session_name') . ":" . $id, "");
         return '';
     }
     return $session;
 }
开发者ID:philippjenni,项目名称:icinga-web,代码行数:14,代码来源:AppKitMemcacheSessionStorage.class.php

示例13: add

 public static function add(string $key, $var, $ttl = 0)
 {
     memcache_add($key, $var, false, $ttl);
 }
开发者ID:TF-Joynic,项目名称:Hydrogen,代码行数:4,代码来源:Memcache.php

示例14: __pagination_concurrent_create_warm_page

function __pagination_concurrent_create_warm_page($mc_handler, $locking_key, $page_key, $query)
{
    $lock = memcache_add($mc_handler, $locking_key, microtime(true));
    if ($lock) {
        $item = db_get_row($query);
        memcache_delete($mc_handler, $locking_key);
        return $item;
    }
    //someone else is updating same page
    $value_changes = 0;
    $known_value = false;
    while (true) {
        $lock = memcache_get($mc_handler, $locking_key);
        if ($lock) {
            if ($known_value != $lock) {
                $value_changes++;
                if ($value_changes > 2) {
                    return memcache_get($mc_handler, $page_key);
                }
                $known_value = $lock;
            }
        } else {
            $lock = memcache_add($mc_handler, $locking_key, microtime(true));
            if ($lock) {
                $item = db_get_row($query);
                memcache_delete($mc_handler, $locking_key);
                return $item;
            } else {
                $value_changes++;
            }
        }
    }
}
开发者ID:plFlok,项目名称:vk_test_task,代码行数:33,代码来源:pagination.php

示例15: define

<?php

define('MEMCACHED_HOST', '127.0.0.1');
define('MEMCACHED_PORT', '11211');
define('MEMCACHED_TIMEOUT', '10');
if (!extension_loaded('memcache')) {
    die('Extension not loaded');
}
if ($cr = memcache_connect(MEMCACHED_HOST, MEMCACHED_PORT, MEMCACHED_TIMEOUT)) {
    $fileContents = 'SSI block added at ' . date('Y/m/d H:i:s', time());
    $flag = false;
    $finalKey = md5(time() + rand(0, 100)) . '.html';
    $fileFinalContents = file_get_contents('./lipsum.txt');
    //the file does not exists
    if (!memcache_replace($cr, $finalKey, $fileFinalContents, $flag, 0)) {
        if (!memcache_add($cr, $finalKey, $fileFinalContents, $flag, 0)) {
            print 'Unable to add file';
        }
    }
    echo '<!--#include memcached="' . $finalKey . '" -->';
} else {
    print 'unable to connect to memcached';
}
开发者ID:jeromer,项目名称:modmemcachedinclude,代码行数:23,代码来源:backendgen.php


注:本文中的memcache_add函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。