Belirtilen birincil anahtar aralığındaki satırları okumak için Tablestore PHP SDK'yı kullanın.
Önkoşullar
Yöntem
public function getRange(array $request)
Örnekler
Birincil anahtarın row1 değerinden büyük olduğu test_table tablosundan verileri okuyun.
$request = array (
'table_name' => 'test_table',
// Set the start primary key
'inclusive_start_primary_key' => array (
array('id', 'row1')
),
// Set the end primary key (the response excludes this key)
'exclusive_end_primary_key' => array (
array('id', null, PrimaryKeyTypeConst::CONST_INF_MAX)
),
// Set forward read
'direction' => DirectionConst::CONST_FORWARD,
// Set the number of versions to read
'max_versions' => 1
);
try {
// Call getRange to read rows
$response = $client->getRange ($request);
// Process the response
echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";
echo "* Row Data: " . "\n";
foreach ($response['rows'] as $row) {
echo json_encode($row) . "\n";
}
} catch (Exception $e){
echo "Get Range failed.";
}
Tek bir aralık taraması en fazla 5.000 satır veya 4 MB veri döndürür. Sonuç bu sınırları aşarsa yanıt bir sonraki başlangıç birincil anahtarını içerir. Kalan verileri okumak için yinelemeli sorgular kullanın.
while (true) {
// Call getRange to read rows
$response = $client->getRange ($request);
// Process the response
echo "* Read CU Cost: " . $response['consumed']['capacity_unit']['read'] . "\n";
echo "* Write CU Cost: " . $response['consumed']['capacity_unit']['write'] . "\n";
echo "* Row Data: " . "\n";
foreach ($response['rows'] as $row) {
echo json_encode($row) . "\n";
}
if ($response['next_start_primary_key'] != null){
$request['inclusive_start_primary_key'] = $response['next_start_primary_key'];
} else {
break;
}
}
Aşağıdaki isteğe bağlı ayarları da yapılandırabilirsiniz:
-
Okuma yönünü ters olarak ayarlayın.
$request = array ( 'table_name' => 'test_table', // Set the start primary key (for backward reads, the start key must be greater than the end key) 'inclusive_start_primary_key' => array ( array('id', null, PrimaryKeyTypeConst::CONST_INF_MAX) ), // Set the end primary key (the response excludes this key) 'exclusive_end_primary_key' => array ( array('id', 'row1') ), // Set backward read 'direction' => DirectionConst::CONST_BACKWARD, // Set the number of versions to read 'max_versions' => 1 ); -
Bir sürüm aralığı belirleyin. Yalnızca belirtilen aralıktaki veriler döndürülür.
// Set the version range to one day before the current time $request['time_range'] = array ( 'start_time' => intval(microtime(true) * 1000) - 86400 * 1000, 'end_time' => intval(microtime(true) * 1000) ); -
Okunacak nitelik sütunlarını belirtin.
$request['columns_to_get'] = array('col2'); -
İstek başına döndürülecek maksimum satır sayısını ayarlayın.
$request['limit'] = 10;