Cette rubrique explique comment mettre à jour la configuration d'une table à l'aide du SDK Tablestore pour .NET.
Prérequis
Le client est initialisé. Pour plus d'informations, consultez la rubrique Initialiser un client Tablestore.
Description de la méthode
public UpdateTableResponse UpdateTable(UpdateTableRequest request)
Méthode asynchrone :
public Task<UpdateTableResponse> UpdateTableAsync(UpdateTableRequest request)
Exemple de code
try
{
UpdateTableRequest request = new UpdateTableRequest("test_table");
// Table configuration information.
TableOptions tableOptions = new TableOptions();
// Specify the TTL in seconds.
tableOptions.TimeToLive = 86400;
// Specify the maximum number of versions.
tableOptions.MaxVersions = 3;
// Specify the maximum version offset in seconds.
tableOptions.DeviationCellVersionInSec = 86400;
// Specify whether updates are allowed.
tableOptions.AllowUpdate = false;
request.TableOptions = tableOptions;
// Enable Stream and set the Stream validity period to seven days.
StreamSpecification streamSpecification = new StreamSpecification(true);
streamSpecification.ExpirationTime = 168;
request.StreamSpecification = streamSpecification;
// Set reserved read throughput to 0 CU and reserved write throughput to 0 CU (you can set this parameter to a non-zero value and the setting takes effect only for data tables in high-performance instances in CU mode).
CapacityUnit reservedThroughput = new CapacityUnit(0, 0);
request.ReservedThroughput = reservedThroughput;
// Call the UpdateTable method to modify the table configurations.
client.UpdateTable(request);
Console.WriteLine("Update table succeeded.");
}
catch (Exception ex)
{
Console.WriteLine($"Update table failed, exception:{ex.Message}");
}