Mettez à jour les configurations de table, telles que le TTL, le nombre maximal de versions, les paramètres Stream et le débit réservé, à l'aide du SDK Tablestore pour Go.
Prérequis
Description de la méthode
func (tableStoreClient *TableStoreClient) UpdateTable(request *UpdateTableRequest) (*UpdateTableResponse, error)
Remarque
Lors de l'appel de la méthode
UpdateTable(), définissez au moins l'un des paramètres TableOption, StreamSpec ou ReservedThroughput.Lors de la définition de TableOption, spécifiez les paramètres TimeToAlive et MaxVersion.
Exemple de code
L'exemple de code suivant modifie les configurations de la table test_table.
func UpdateTableSample(client *tablestore.TableStoreClient) {
updateTableReq := new(tablestore.UpdateTableRequest)
updateTableReq.TableName = "test_table"
// Table configuration.
updateTableReq.TableOption = new(tablestore.TableOption)
// Set the time to live (TTL), in seconds.
updateTableReq.TableOption.TimeToAlive = 86400
// Set the maximum number of versions.
updateTableReq.TableOption.MaxVersion = 3
// Set the maximum version offset, in seconds.
updateTableReq.TableOption.DeviationCellVersionInSec = 86400
// Specify whether to allow data updates.
updateTableReq.TableOption.AllowUpdate = proto.Bool(false)
// Enable Stream and set the Stream expiration time to 7 days.
// When you modify the ExpirationTime parameter, you must also set EnableStream to true.
updateTableReq.StreamSpec = new(tablestore.StreamSpecification)
updateTableReq.StreamSpec.EnableStream = true
updateTableReq.StreamSpec.ExpirationTime = 168
// Set the reserved read throughput to 0 CU and the reserved write throughput to 0 CU.
// Non-zero throughput is applicable only to high-performance instances in CU mode.
updateTableReq.ReservedThroughput = new(tablestore.ReservedThroughput)
updateTableReq.ReservedThroughput.Readcap = 0
updateTableReq.ReservedThroughput.Writecap = 0
// Call the UpdateTable method to update the table configuration.
_, err := client.UpdateTable(updateTableReq)
if (err != nil) {
fmt.Println("Failed to update table with error:", err)
} else {
fmt.Println("Update table finished.")
}
}