如何实现“自动增量"在 Google AppEngine 上 [英] How to implement "autoincrement" on Google AppEngine

查看:23
本文介绍了如何实现“自动增量"在 Google AppEngine 上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须以强烈单调递增"的方式标记某些东西.无论是发票编号、运输标签编号等.

I have to label something in a "strong monotone increasing" fashion. Be it Invoice Numbers, shipping label numbers or the like.

  1. 一个数字不得重复使用
  2. 当使用了所有较小的数字(没有空洞)时,应该使用每个数字.

花哨的说法:我需要数 1,2,3,4 ...我可用的号码空间通常是 100.000 个号码,而我每天可能需要 1000 个.

Fancy way of saying: I need to count 1,2,3,4 ... The number Space I have available are typically 100.000 numbers and I need perhaps 1000 a day.

我知道这是分布式系统中的一个难题,而且通常我们使用 GUID 会更好.但在这种情况下,出于法律原因,我需要传统编号".

I know this is a hard Problem in distributed systems and often we are much better of with GUIDs. But in this case for legal reasons I need "traditional numbering".

这可以在 Google AppEngine 上实现吗(最好是在 Python 中)?

Can this be implemented on Google AppEngine (preferably in Python)?

推荐答案

如果您绝对需要无间隙地按顺序增加数字,则需要使用单个实体,您可以在事务中将其更新为消费"每个新号码.实际上,您将被限制为每秒生成大约 1-5 个数字 - 这听起来可以满足您的要求.

If you absolutely have to have sequentially increasing numbers with no gaps, you'll need to use a single entity, which you update in a transaction to 'consume' each new number. You'll be limited, in practice, to about 1-5 numbers generated per second - which sounds like it'll be fine for your requirements.

这篇关于如何实现“自动增量"在 Google AppEngine 上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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