本文整理匯總了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]);
}