如何检测 SimpleDB 域是否包含请求的项?

How to detect if SimpleDB domain contains the requested item?

Ruby SDK 的 AWS SimpleDB documentation 提供了以下关于使用 get_attributes 方法的示例:

resp = client.get_attributes({
  domain_name: "String", # required
  item_name: "String", # required
  attribute_names: ["String"],
  consistent_read: false,
})

...然后是以下示例响应:

resp.attributes #=> Array
resp.attributes[0].name #=> String
resp.attributes[0].alternate_name_encoding #=> String
resp.attributes[0].value #=> String
resp.attributes[0].alternate_value_encoding #=> String

它还提出了以下建议:

If the item does not exist on the replica that was accessed for this operation, an empty set is returned. The system does not return an error as it cannot guarantee the item does not exist on other replicas.

我希望我误解了这一点,但如果您的回复 return 是一个空集,那么您应该如何知道这是因为提供的项目名称不存在任何项目,或者您的请求只是击中了一个不包含您的项目的副本?

我以前从未使用过 AWS SimpleDB,但根据我对从 Amazon 的 DynamoDB 进行复制的了解很少,数据通常最终是一致的 - 虽然任何副本都会处理您读取属性的请求,但复制过程之前写入数据仍然可以在负责存储数据的副本之间进行,这就是为什么处理您的请求以读取属性的副本可能不必存储数据(还) - 这就是它无法响应错误消息的原因.

为了 100% 确定您应该能够做的是指定 consistent_read: true 参数,因为它应该告诉您数据是否存在于 AWS SimpleDB 中:

according to the documentation of get_attributes method

:consistent_read (Boolean) —

Determines whether or not strong consistency should be enforced when data is read from SimpleDB. If true, any data previously written to SimpleDB will be returned. Otherwise, results will be consistent eventually, and the client may not see data that was written immediately before your read.