DynamoDB avoid duplicate non-key attributes

霸气de小男生 提交于 2019-12-12 03:25:33

问题


I have a user object with these attributes.

id (key), name and email

And I am trying to make sure these attributes are unique in the DB.

How do I prevent a put/create/save operation from succeeding, in case of either of the non-key attributes, email and name, already exists in the DB?

I have a table, tblUsers with one key-attribute being the id. I then have two globally secondary indexes, each with also one key-attribute, being the email for the first index-table, and name for the second.

I am using microsoft .net identity framework, which itself checks for existing users with a given name or email, before creating a user.

The problem I forsee, is the delay between checking for existing users and creating a new. There is no safety, that multiple threads wont end up creating two users with the same name or email.


回答1:


dynamodb can force uniqueness only for hash-range table keys (not for global secondary index keys)

do in your case there are 2 options:

1) force it on application level - if your problem is safety, then use locks (cache locks)

2) dont use dynamodb (maybe its not answer your requirements )




回答2:


I am using ehcache locally to check for duplicates . Adding one more check if ehcache is empty (for some reason ,cache has been reset ) .repopulate cache by making query to dynamoDb .



来源:https://stackoverflow.com/questions/35387768/dynamodb-avoid-duplicate-non-key-attributes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!