DynamoDB避免重复非关键属性 [英] DynamoDB avoid duplicate non-key attributes

查看:428
本文介绍了DynamoDB避免重复非关键属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这些属性的用户对象。

I have a user object with these attributes.

ID (键),名称电子邮件

和我想,以确保这些属性在DB是独一无二的。

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

我如何prevent一个 / 创建 / 保存运行得手,在任非关键属性的情况下,电子邮件名称,在数据库中已存在?

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?

我有一个表,向tblUsers 有一个关键的属性作为 ID
然后我有两个全球二级指标,每个也是一个关键的属性,作为电子邮件第一个索引表,和名称第二。

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.

我使用的Microsoft .NET框架的身份,这本身就检查现有用户具有给定名称或电子邮件,创建用户之前。

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.

推荐答案

dynamodb可以强制唯一只对哈希表范围键(不适用于全球二级索引键)

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

做在你的案件有2个选项:

do in your case there are 2 options:

1),迫使其在应用层面 - 如果你的问题是安全性,然后用锁(锁缓存)

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

2)不使用dynamodb(也许它没有回答您的要求)

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

这篇关于DynamoDB避免重复非关键属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆