本文整理汇总了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;
}
示例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);
}
示例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");
}
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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;
}
}
示例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;
}
示例11: add
public static function add($key, $value, $expire = 0)
{
return \memcache_add(self::$connection, $key, $value, self::$flags, $expire);
}
示例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;
}
示例13: add
public static function add(string $key, $var, $ttl = 0)
{
memcache_add($key, $var, false, $ttl);
}
示例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++;
}
}
}
}
示例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';
}