問題描述
DynamoDB 提供了用于刪除項(xiàng)目的 API.在返回的 DeleteItemOutcome
和 DeleteItemResult
中沒有字段或方法來確定是否找到了 key 并且該項(xiàng)目確實(shí)被刪除了.
DynamoDB provides an API for deleting items. In the returned DeleteItemOutcome
and DeleteItemResult
there is no field or method to determine if the key was found and the item was indeed deleted.
確定該項(xiàng)目是否確實(shí)存在和刪除的唯一方法是請求項(xiàng)目的屬性:
The only way to find out if the item was indeed present and deleted, is to request the items' attributes:
新的 DeleteItemSpec().withPrimaryKey("key","1").withReturnValues(ReturnValue.ALL_OLD))
但是,這會消耗額外的讀取容量.有沒有更有效的方法來檢查刪除結(jié)果 - 找到和刪除的鍵/無效鍵?
This, however, consumes extra read capacity. Is there a more efficient way to check the delete result - key found and deleted / invalid key?
推薦答案
DeleteItemResult#getAttributes()
是 方法 來確定一個 DeleteItem
操作實(shí)際上已經(jīng)刪除了一個項(xiàng)目,或者沒有.
DeleteItemResult#getAttributes()
is the way to determine if a DeleteItem
operation has actually deleted an item, or not.
如果您指定 ReturnValue.ALL_OLD
并且項(xiàng)目被刪除,則返回項(xiàng)目屬性映射,否則返回空映射.這是確定操作是否成功的唯一方法.API 不會返回其他確認(rèn)信息.
If you specify ReturnValue.ALL_OLD
and the item was deleted, a map of item attributes is returned, otherwise and empty map is returned. This is the only way to know for sure if the operation was successful. No other confirmation is returned by the API.
請記住,DeleteItem
操作每次至少會消耗 1 個寫入容量單位.如果刪除的item大于1KB,消耗的容量會大于1.
Keep in mind that a DeleteItem
operation will consume a minimum of 1 write capacity unit every time. If the deleted item is larger than 1KB, consumed capacity will be more than 1.
供參考: http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CapacityUnitCalculations.html#ItemSizeCalculations.Writes
這篇關(guān)于如何確定是否確實(shí)刪除了 DynamoDB 項(xiàng)目?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!