本文整理汇总了PHP中Aws\DynamoDb\DynamoDbClient::batchGetItem方法的典型用法代码示例。如果您正苦于以下问题:PHP DynamoDbClient::batchGetItem方法的具体用法?PHP DynamoDbClient::batchGetItem怎么用?PHP DynamoDbClient::batchGetItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\DynamoDb\DynamoDbClient
的用法示例。
在下文中一共展示了DynamoDbClient::batchGetItem方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batchGet
/**
* Get a batch of items
* @param Context\BatchGet $context
* @throws \Riverline\DynamoDB\Exception\AttributesException
* @return \Riverline\DynamoDB\Batch\BatchCollection
*/
public function batchGet(Context\BatchGet $context)
{
if (null !== $this->logger) {
$this->log('BatchGet');
}
if (0 === count($context)) {
$message = "BatchGet context doesn't contain any key to get";
if (null !== $this->logger) {
$this->log($message, Logger::ERROR);
}
throw new Exception\AttributesException($message);
}
$parameters = $context->getForDynamoDB();
if (null !== $this->logger) {
$this->log('BatchGet request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
}
$response = $this->connector->batchGetItem($parameters);
if (null !== $this->logger) {
$this->log('BatchGet request response : ' . print_r($response, true), Logger::DEBUG);
}
// UnprocessedKeys
if (count((array) $response['UnprocessedKeys'])) {
$unprocessKeyContext = new Context\BatchGet();
foreach ($response['UnprocessedKeys'] as $table => $tableParameters) {
foreach ($tableParameters->Keys as $key) {
$unprocessKeyContext->addKey($table, current($key->HashKeyElement), current($key->RangeKeyElement));
}
if (!empty($tableParameters->AttributesToGet)) {
$unprocessKeyContext->setAttributesToGet($table, $tableParameters->AttributesToGet);
}
}
} else {
$unprocessKeyContext = null;
}
$collection = new Batch\BatchCollection($unprocessKeyContext);
foreach ($response['Responses'] as $table => $responseItems) {
$this->addConsumedReadUnits($table, floatval($responseItems['ConsumedCapacityUnits']));
$items = new Collection();
foreach ($responseItems['Items'] as $responseItem) {
$item = new Item($table);
$item->populateFromDynamoDB($responseItem);
$items->add($item);
}
if (null !== $this->logger) {
$this->log('Find ' . count($items) . ' Items on table ' . $table);
}
$collection->setItems($table, $items);
}
return $collection;
}
示例2: batchGetItem
/**
* Executes the BatchGetItem operation.
*
* @param array $requestItems Associative array of <TableName> keys mapping to (associative-array) values.
* @param string $returnConsumedCapacity Sets consumed capacity return mode.
*
* @return Guzzle\Service\Resource\Model
*
* @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_batchGetItem
*/
public function batchGetItem(array $requestItems, $returnConsumedCapacity = self::CAPACITY_NONE)
{
$args = ['RequestItems' => $requestItems, 'ReturnConsumedCapacity' => $returnConsumedCapacity];
// Try to load from cache is a cacheService is available
if ($this->cacheService !== null) {
$cacheKey = $this->generateCacheKey($args);
if ($this->cacheService->has($cacheKey)) {
return unserialize($this->cacheService->get($cacheKey));
}
}
// Sends batchGetItem command to AWS
$result = $this->client->batchGetItem($args);
// Saves to cache
if ($this->cacheService !== null) {
$this->cacheService->set($cacheKey, serialize($result), $this->requestTtl);
}
return $result;
}
示例3: batchGetItems
/**
* Retrieve items in batches of up to 100
*
* @param array $key_values
*
* HashKey: [hash_key_value1, hash_key_value2 ..]
* HashKey + RangeKey: [[hash_key_value1, range_key_value1] ...]
*
* @return self[]
*/
public function batchGetItems(array $key_values)
{
$keys = array();
foreach ($key_values as $key_value) {
if ($this->_range_key) {
$conditions = array($this->_hash_key => $key_value[0], $this->_range_key => $key_value[1]);
} else {
$_id = is_array($key_value) ? $key_value[0] : $key_value;
$conditions = array($this->_hash_key => $_id);
}
$keys[] = $this->_formatAttributes($conditions);
}
$result = self::$_client->batchGetItem(array('RequestItems' => array($this->_table_name => array('Keys' => $keys, 'ConsistentRead' => true))));
$items = $result->getPath("Responses/{$this->_table_name}");
$class_name = get_called_class();
$formatted_result = $this->_formatResults($items);
$array = array();
foreach ($formatted_result as $row) {
$instance = self::factory($class_name);
$instance->hydrate($row);
$array[] = $instance;
}
return $array;
}