Python:在 Google App Engine 中存储数字
我正在使用 Google App Engine Python。
我想在某个地方存储一个简单的变量数字,这样我就可以添加、扣除和使用这个数字。
examplenum=5
example+=1
下次我使用这个 examplenum 时,它将变成 6。
我知道我可以构建一个 Model
并添加一个 IntegerProperty
变量。但我想这太麻烦了,因为我只需要一个简单的数字而不是模型。
我也读过这个问题Simplest way to store Google App Engine Python 中的值?,memcache
解决方案不适合我。我希望该号码永远保留在 memcache
中,而不仅仅是临时的。
多谢。
I am using Google App Engine Python.
I would like to store a simple variable number somewhere, so I can add, deduct and use this number.
examplenum=5
example+=1
Next time I use this examplenum, it wil become 6.
I know I can build a Model
and add an IntegerProperty
varible. But I guess that would be too much hassle because I only need one simple number not a model.
I have also read this question Simplest way to store a value in Google App Engine Python?, the memcache
solution is not good for me. I want the number to stay forever not just temporary in the memcache
.
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您链接的问题的所有答案都与您相关。如果你想要持久性,你就必须创建一个模型。查看使用 get_or_insert 获取/初始化实体并为您提供实体一个
key_name
,以便您可以在需要存储值时轻松获取它。您的代码看起来确实像计数器,您可能需要查看分片计数器 文章及其解决的问题(如果相关)。
All the answers to the question you linked are relevent to you. If you want persistance you will have to create a model. Look at using get_or_insert to fetch/initialize an entity and give your entity a
key_name
so that you can keep fetching it easily whenever you need to store your values.You code does look suspiciously like a counter, and you might want to look at the sharding countering article and the problems that it solves in case they are relevent.