gpt4 book ai didi

c++ - 如何在C++中对DynamoDB GetItem()启用ConsistentRead

转载 作者:行者123 更新时间:2023-12-02 10:28:20 35 4
gpt4 key购买 nike

根据Aws SDK documentation,默认情况下,GetItem()提供最终一致的读取。如何将ConsistentRead设置为true以在代码中启用强一致性读取?

template<typename T>
bool DynamoDBClient::GetItemByKey(const std::string& table, const std::string& key_name, const std::string& key_value, const std::string& projection_expr, T& result) {
Aws::SDKOptions options;
options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
AWS::InitAPI(options);

// Set up request.
Aws::DynamoDB::Model::GetItemRequest gir;
gir.SetTableName(String2AwsString(table));
Aws::DynamoDB::Model::AttributeValue hashKey;
hashKey.setS(String2AwsString(key_value));
gir.AddKey(String2AwsString(key_name), hashKey);
if (!projection_expr.empty()) {
gir.SetProjectionExpression(projection_expr);
}

// Retrieve item from table.
const Aws::DynamoDB::Model::GetItemOutcome& result = dynamodb_client_->GetItem(gir);
...
}

最佳答案

如Oliver所指出的,可以通过GetItemRequest::SetConsistentRead()或GetItemRequestWithConsistentRead()方法启用/禁用 ConsistentRead 标志,如下所示:

// Set up request.
Aws::DynamoDB::Model::GetItemRequest gir;
gir.SetTableName(String2AwsString(table));
gir.SetConsistentRead(true);

关于c++ - 如何在C++中对DynamoDB GetItem()启用ConsistentRead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63332455/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com