Random string query in ndb

I am trying to create a web application in a google application using webapp2.

One of the things I need to do is get random from ndb and display it. Is this an effective method that allows me to do this?

+2
source share
3 answers

I assume that you mean random recording when you say "random from ndb".

If you use an automatic identifier, you can use the following approach. (how your sparse identifier will affect the success of this).

use random.randrange(start, stop)with a start of 0, stop being (2 ^ 52) -1, given the new identifier allocation policy.

, , , . < .

10 ( )

random.choice(seq) , .

key.get() .

< 1000

, random.choice() a db.get() . , . , , 1 , memcache.

+3

. , /.

+2

, : 1, yourquery = entitykind.query()

2, yourquery.count()

3,

4, for ,

yourquery.fetch()

and then when the number of cycles that have been executed equals the random number above, use the specific object in your web application

0
source

Source: https://habr.com/ru/post/1525940/


All Articles