本文整理汇总了PHP中Aws\DynamoDb\DynamoDbClient::batchWriteItem方法的典型用法代码示例。如果您正苦于以下问题:PHP DynamoDbClient::batchWriteItem方法的具体用法?PHP DynamoDbClient::batchWriteItem怎么用?PHP DynamoDbClient::batchWriteItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Aws\DynamoDb\DynamoDbClient
的用法示例。
在下文中一共展示了DynamoDbClient::batchWriteItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: batchWrite
/**
* Put Items and delete Keys by batch
* @param Context\BatchWrite $context
* @return null|Context\BatchWrite Return a new BatchWrite context if some request were not processed
* @throws Exception\AttributesException
*/
public function batchWrite(Context\BatchWrite $context)
{
if (null !== $this->logger) {
$this->log('BatchWrite');
}
if (0 === count($context)) {
$message = "BatchWrite context doesn't contain anything to write";
if (null !== $this->logger) {
$this->log($message, Logger::ERROR);
}
throw new Exception\AttributesException($message);
}
$parameters = $context->getForDynamoDB();
if (null !== $this->logger) {
$this->log('BatchWrite request paramaters : ' . print_r($parameters, true), Logger::DEBUG);
}
$response = $this->connector->batchWriteItem($parameters);
if (null !== $this->logger) {
$this->log('BatchWrite request response : ' . print_r($response, true), Logger::DEBUG);
}
// UnprocessedKeys
if (count((array) $response['UnprocessedItems'])) {
$newContext = new Context\BatchWrite();
foreach ($response['UnprocessedItems'] as $table => $tableParameters) {
foreach ($tableParameters as $request) {
if (isset($request['DeleteRequest'])) {
$keys = $request['DeleteRequest']['Key'];
$newContext->addKeyToDelete($table, current($keys['HashKeyElement']), isset($keys['RangeKeyElement']) ? current($keys['RangeKeyElement']) : null);
} elseif (isset($request['PutRequest'])) {
$item = new Item($table);
$item->populateFromDynamoDB($request['PutRequest']['Item']);
$newContext->addItemToPut($item);
}
}
}
if (null !== $this->logger) {
$this->log('More unprocessed Items');
}
} else {
$newContext = null;
}
// Write Unit
foreach ($response['Responses'] as $table => $responseItems) {
$this->addConsumedWriteUnits($table, floatval($responseItems['ConsumedCapacityUnits']));
}
return $newContext;
}
示例2: batchWriteItem
/**
* Executes the BatchWriteItem operation.
*
* @param array $requestItems Associative array of <TableName> keys mapping to (array<associative-array>) values.
* @param string $returnConsumedCapacity Sets consumed capacity return mode.
* @param string $returnItemCollectionMetrics If set to SIZE, statistics about item collections, if any, that were modified during the operation are returned in the response.
*
* @return Guzzle\Service\Resource\Model
*
* @see http://docs.aws.amazon.com/aws-sdk-php/latest/class-Aws.DynamoDb.DynamoDbClient.html#_batchWriteItem
*/
public function batchWriteItem(array $requestItems, $returnConsumedCapacity = self::CAPACITY_NONE, $returnItemCollectionMetrics = self::METRICS_NONE)
{
return $this->client->batchWriteItem(['RequestItems' => $requestItems, 'ReturnConsumedCapacity' => $returnConsumedCapacity, 'ReturnItemCollectionMetrics' => $returnItemCollectionMetrics]);
}