本文介绍了Google Cloud数据存储区中的组合键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GCP数据存储区中我有3种属性.

In GCP Datastore & I've a kind with 3 properties.

  1. 密钥(自动生成)
  2. externalId
  3. externalName

我不允许重复的externalName + externalId组合.可以保持这种独特性吗?

I can't allow duplicate externalName + externalId combination. Is it possible to maintain this uniqueness?

推荐答案

选项:

  1. 尽管您想使用externalId& ;;的串联,但是请执行Robert在他的回答中所说的话. externalName作为键.唯一的缺点是如果externalIdexternalName更改,那么您将无法更改密钥.您必须删除当前对象并创建一个新对象;可能会对具有指向该对象的关键属性的其他任何对象产生级联影响.
  2. 在保存之前检查Model.query(Model.externalId== externalId, Model.externalName == externalName).count(1) > 0.这里的缺点是,获取键是高度一致的,但是查询最终是一致的.这意味着,如果2个线程同时提交同一对线程对,那么这两个线程都会成功.
  3. 将唯一组合保存在一个键中,但是保存在一个单独的表中,该表称为Unique.这是webapp2的源代码中的一个示例,他们正是这样做的. https://github.com/GoogleCloudPlatform/webapp2/blob/master/webapp2_extras/appengine/auth/models.py#L33
  1. Do what Robert said in his answer, although you would want to using the concatenation of externalId & externalName as the key. The only downside of this is if externalId or externalName change, then you wouldn't be able to change your key. You'd have to delete the current object and make a new one; which could have cascading impacts on any other object with key properties that point to this object.
  2. Check for Model.query(Model.externalId== externalId, Model.externalName == externalName).count(1) > 0 before you save. Downside here is that fetching a key is strongly consistent, but queries are eventually consistent. This means if 2 threads submitting the same pair at the same time would both succeed.
  3. Save the unique combo in a key, but in a separate table called Unique. Here's an example from webapp2's source code where they did just that. https://github.com/GoogleCloudPlatform/webapp2/blob/master/webapp2_extras/appengine/auth/models.py#L33

这篇关于Google Cloud数据存储区中的组合键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 20:58