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; }
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); }
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"); } }
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); }
function cache_add($key, $data, $expires) { $connection = cache_connect(); $res = memcache_add($connection, (string) $key, $data, false, (int) $expires); memcache_close($connection); return $res; }
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); } }
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); } }
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(); }
/** * Функция взятия блокировки для изменения заказа * @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; } }
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; }
public static function add($key, $value, $expire = 0) { return \memcache_add(self::$connection, $key, $value, self::$flags, $expire); }
/** * 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; }
public static function add(string $key, $var, $ttl = 0) { memcache_add($key, $var, false, $ttl); }
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++; } } } }
<?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'; }
function addToCache($key, $item) { global $memcacheServerName, $memcachePort; $memcache_obj = memcache_connect($memcacheServerName, $memcachePort); memcache_add($memcache_obj, $key, $item, false, 60); }
echo 'sms'; //exit('sms'); } } $mailMsgKey = implode('|', array('mail_msg', $submodule['id'])); $mailMsgInitRes = memcache_add($mc, $mailMsgKey, 1, false, 3600); if ($mailMsgInitRes === false) { $mailMsgCount = memcache_increment($mc, $mailMsgKey, 1); } else { $mailMsgCount = 1; } echo $mailMsgCount; $mailWarningKey = implode('|', array('mail', $submodule['id'])); if ($mailMsgCount >= $submodule['mail_limit'] && $submodule['mail_status']) { //sendmail $mailLock = memcache_add($mc, $mailWarningKey, 1, false, 600); if ($mailLock === true) { $arr = $matches = array(); preg_match("/^SELECTED:\\[(.*)\\]\$/", $project['monitors'], $matches); $str = str_replace('\'', '"', "[" . $matches[1] . "]"); $projectUids = json_decode($str, true); $arr = $matches = array(); if (!empty($submodule['monitors'])) { preg_match("/^SELECTED:\\[(.*)\\]\$/", $submodule['monitors'], $matches); $str = str_replace('\'', '"', "[" . $matches[1] . "]"); $submoduleUids = json_decode($str, true); $uids = array_merge($projectUids, $submoduleUids); } else { $uids = $projectUids; } $mailsResult = mysqli_query($connSlave, 'SELECT email FROM `monitor` WHERE id IN (' . implode(',', $uids) . ')');