$batch_get_response = $dynamodb->batch_get_item(array( 'RequestItems' => array( 'products' => array( 'Keys' => array( array( // Key #1 'HashKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => '1'),'RangeKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => $current_time),),array( // Key #2 'HashKeyElement' => array( AmazonDynamoDB::TYPE_NUMBER => '2'),) ) ) ));
是否可以选择所有项目而不指定主键?我正在使用AWS SDK for PHP.
>根据您的表大小,您可能需要使用分页来检索整个结果集:
Note
If the total number of scanned items exceeds the 1MB limit,the
scan stops and results are returned to the user with a
LastEvaluatedKey to continue the scan in a subsequent operation. The
results also include the number of items exceeding the limit. A scan
can result in no table data meeting the filter criteria.The result set is eventually consistent.
>扫描操作在性能和消耗的容量单元(即价格)方面可能是昂贵的,请参阅Query and Scan in Amazon DynamoDB中的“扫描和查询性能”部分:
[…] Also,as a table grows,the scan operation slows. The scan
operation examines every item for the requested values,and can use up
the provisioned throughput for a large table in a single operation.
For quicker response times,design your tables in a way that can use
the Query,Get,or BatchGetItem APIs,instead. Or,design your
application to use scan operations in a way that minimizes the impact
on your table’s request rate. For more information,see 07003. [emphasis mine]
您可以在Scanning Tables Using the AWS SDK for PHP Low-Level API for Amazon DynamoDB中找到有关此操作和一些示例代码段的更多详细信息,其中最简单的示例说明了操作:
$dynamodb = new AmazonDynamoDB(); $scan_response = $dynamodb->scan(array( 'TableName' => 'ProductCatalog' )); foreach ($scan_response->body->Items as $item) { echo "<p><strong>Item Number:</strong>" . (string) $item->Id->{AmazonDynamoDB::TYPE_NUMBER}; echo "<br><strong>Item Name: </strong>" . (string) $item->Title->{AmazonDynamoDB::TYPE_STRING} ."</p>"; }