如何实现“自动增量”在Google AppEngine上 [英] How to implement "autoincrement" on 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,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屋!