當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Memcached::setMultiByKey方法代碼示例

本文整理匯總了PHP中Memcached::setMultiByKey方法的典型用法代碼示例。如果您正苦於以下問題:PHP Memcached::setMultiByKey方法的具體用法?PHP Memcached::setMultiByKey怎麽用?PHP Memcached::setMultiByKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Memcached的用法示例。


在下文中一共展示了Memcached::setMultiByKey方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setMulti

 /**
  * Set multiple values to cache at once.
  *
  * By sending an array of $items to this function, all values are saved at once to
  * memcached, reducing the need for multiple requests to memcached. The $items array
  * keys and values are what are stored to memcached. The keys in the $items array
  * are merged with the $groups array/string value via buildKeys to determine the
  * final key for the object.
  *
  * @link    http://www.php.net/manual/en/memcached.setmulti.php
  *
  * @param   array           $items          An array of key/value pairs to store on the server.
  * @param   string|array    $groups         Group(s) to merge with key(s) in $items.
  * @param   int             $expiration     The expiration time, defaults to 0.
  * @param   string          $server_key     The key identifying the server to store the value on.
  * @param   bool            $byKey          True to store in internal cache by key; false to not store by key
  * @return  bool                            Returns TRUE on success or FALSE on failure.
  */
 public function setMulti($items, $groups = 'default', $expiration = 0, $server_key = '', $byKey = false)
 {
     // Build final keys and replace $items keys with the new keys
     $derived_keys = $this->buildKeys(array_keys($items), $groups);
     $expiration = $this->sanitize_expiration($expiration);
     $derived_items = array_combine($derived_keys, $items);
     $group_offset = empty($this->cache_key_salt) ? 1 : 2;
     // Do not add to memcached if in no_mc_groups
     foreach ($derived_items as $derived_key => $value) {
         // Get the individual item's group
         $key_pieces = explode(':', $derived_key);
         // If group is a non-Memcached group, save to runtime cache, not Memcached
         if (in_array($key_pieces[$group_offset], $this->no_mc_groups)) {
             $this->add_to_internal_cache($derived_key, $value);
             unset($derived_items[$derived_key]);
         }
     }
     // Save to memcached
     if (false !== $byKey) {
         $result = $this->mc->setMultiByKey($server_key, $derived_items, $expiration);
     } else {
         $result = $this->mc->setMulti($derived_items, $expiration);
     }
     // Store in runtime cache if add was successful
     if (Memcached::RES_SUCCESS === $this->getResultCode()) {
         $this->cache = array_merge($this->cache, $derived_items);
     }
     return $result;
 }
開發者ID:Ramoonus,項目名稱:wp-spider-cache,代碼行數:47,代碼來源:class-object-cache.php

示例2: array

    }
    return true;
}
$data = array('foo' => 'foo-data', 'bar' => 'bar-data', 'baz' => 'baz-data', 'lol' => 'lol-data', 'kek' => 'kek-data');
$keys = array_keys($data);
$null = null;
$m->setMulti($data, 3600);
/* Check that all keys were stored */
var_dump(has_all_keys($keys, $m->getMulti($keys)));
/* Check that all keys get deleted */
$deleted = $m->deleteMulti($keys);
var_dump(has_all_keys($keys, $deleted, true));
/* Try to get the deleted keys, should give empty array */
var_dump($m->getMulti($keys));
/* ---- same tests for byKey variants ---- */
$m->setMultiByKey("hi", $data, 3600);
var_dump(has_all_keys($keys, $m->getMultiByKey('hi', $keys)));
/* Check that all keys get deleted */
$deleted = $m->deleteMultiByKey('hi', $keys);
var_dump(has_all_keys($keys, $deleted, true));
/* Try to get the deleted keys, should give empty array */
var_dump($m->getMultiByKey('hi', $keys));
/* Test deleting non-existent keys */
$keys = array();
$keys[] = "nothere";
$keys[] = "nothere2";
$retval = $m->deleteMulti($keys);
foreach ($retval as $key => $value) {
    if ($value === Memcached::RES_NOTFOUND) {
        echo "{$key} NOT FOUND\n";
    }
開發者ID:badlamer,項目名稱:hhvm,代碼行數:31,代碼來源:deletemulti.php

示例3: setMultiByKey

 /**
  * @inheritdoc
  */
 public function setMultiByKey($server_key, array $items, $expiration = null)
 {
     $items = $this->prefixArrayKeys($items);
     return parent::setMultiByKey($server_key, $items, $expiration);
 }
開發者ID:jonafrank,項目名稱:memcached-manager,代碼行數:8,代碼來源:MemcachedHandler.php


注:本文中的Memcached::setMultiByKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。