示例#1
0
 /**
  * Similar to Memcached::get(), but instead of a single key item, it retrieves
  * multiple items the keys of which are specified in the keys array.
  *
  * @see Memcached::get()
  *
  * @param array $keys Array of keys to retrieve.
  * @param array $cas_tokens The variable to store the CAS tokens for found
  * items.
  * @param int $flags The flags for the get operation.
  *
  * @return array The array of found items for false on failure.
  */
 public function getMulti($keys, &$cas_tokens = null, $flags = 0)
 {
     $request = new MemcacheGetRequest();
     $response = new MemcacheGetResponse();
     foreach ($keys as $key) {
         $key = $this->getPrefixKey($key);
         $request->addKey($key);
     }
     // Need to check the number of arguments passed to the function to see if
     // the user wants cas_tokens.
     if (func_num_args() > 1) {
         $request->setForCas(true);
     }
     try {
         ApiProxy::makeSyncCall('memcache', 'Get', $request, $response);
     } catch (Error $e) {
         $this->result_code = self::RES_FAILURE;
         return false;
     }
     $return_value = array();
     foreach ($response->getItemList() as $item) {
         try {
             $return_value[$item->getKey()] = MemcacheUtils::deserializeValue($item->getValue(), $item->getFlags());
         } catch (\UnexpectedValueException $e) {
             // Skip entries that cannot be deserialized.
             continue;
         }
         if ($item->hasCasId()) {
             $cas_tokens[$item->getKey()] = $item->getCasId();
         }
     }
     // If GET_PRESERVE_ORDER was set then we need to ensure that
     // a. Keys are returned in the order that they we asked for.
     // b. If a key has no value then return null for that key.
     if ($flags == self::GET_PRESERVE_ORDER) {
         $ordered_result = [];
         $ordered_cas_tokens = [];
         foreach ($keys as $key) {
             if (array_key_exists($key, $return_value)) {
                 $ordered_result[$key] = $return_value[$key];
                 if (array_key_exists($key, $cas_tokens)) {
                     $ordered_cas_tokens[$key] = $cas_tokens[$key];
                 } else {
                     $ordered_cas_tokens[$key] = null;
                 }
             } else {
                 $ordered_result[$key] = null;
                 $ordered_cas_tokens[$key] = null;
             }
         }
         $return_value = $ordered_result;
         if (func_num_args() > 1) {
             $cas_tokens = $ordered_cas_tokens;
         }
     }
     return $return_value;
 }
示例#2
0
 private function getMulti($keys, $flags = null)
 {
     $request = new MemcacheGetRequest();
     $response = new MemcacheGetResponse();
     foreach ($keys as $key) {
         $request->addKey($key);
     }
     ApiProxy::makeSyncCall('memcache', 'Get', $request, $response);
     $return_value = array();
     foreach ($response->getItemList() as $item) {
         try {
             $return_value[$item->getKey()] = MemcacheUtils::deserializeValue($item->getValue(), $item->getFlags());
         } catch (\UnexpectedValueException $e) {
             // Skip entries that cannot be deserialized.
         }
     }
     return $return_value;
 }
 private function getMulti($keys, $flags = null)
 {
     $request = new MemcacheGetRequest();
     $response = new MemcacheGetResponse();
     foreach ($keys as $key) {
         $request->addKey($key);
     }
     ApiProxy::makeSyncCall('memcache', 'Get', $request, $response);
     $return_value = array();
     foreach ($response->getItemList() as $item) {
         $return_value[$item->getKey()] = MemcacheUtils::deserializeValue($item->getValue(), $item->getFlags());
     }
     return $return_value;
 }