Key Generation in Google App Engine

If you have ever used the Google App Engine. It generates a key for each individual instance of the created model. This is pretty neat.

I look at creating something like that. Do they make it so that the key is content based? Or do they just take a random selection from a-zA-Z0-9over 50 times and build a string from it? This sounds reasonable, because the chances of 2 keys being the same will be lower than 1/10 ^ 89.

+3
source share
4 answers

Just using random values ​​is not going to shorten it. While the likelihood that the two keys will be the same is very small, the chances quickly increase with the number of keys generated. See birthday paradox .

In most cases, such keys are generated in such a way as to guarantee uniqueness with the help of several values, such as the MAC address or any serial number of the server that generated it, time stamp, value of a special counter.

+3
source

You can find more information on how to create a universal unique identifier here .

If you want to create it from the side of php code, you can use the function uniqid. More details here .

+1

Engine :

  • - , .

  • .

  • Either an auto-generated integer identifier, or a user-assigned key name. Integer identifiers are allocated in blocks increasing in ascending order to different instances of the application, so that they can be guaranteed unique, but not guaranteed that they can be assigned to objects in a monotonously increasing way.

Keys do not use anything like a universally unique identifier.

+1
source

It may not be 100% unique, but I'm using something like this:

def get_unique_id_str():
    import binascii
    import uuid
    table = ''.join(chr(i) for i in xrange(256))
    return binascii.b2a_base64(uuid.uuid4().bytes).translate(table, '/+=\n')

key_name = get_unique_id_str()
instance = MyModel(key_name=key_name, ...)
...
0
source

All Articles