java - Generating Hash codes with Google App Engine (GAE) -
i need design way provide hash every document stored in application.
using existing hash libraries (bcrypt
, etc) , bson objectid
generates nice "hash" or "key" quite long.
i understand way achieve short hash, hash fewer strings (if not mistaken). hash long
id's staring 0, 1, 2, 3
, on.
however easy think of, hard implement in google app engine (gae) datastore, or haven't crossed need until now.
the gae datastore store entities across severs , across datacenters , auto-increment id not this.
what strategy achieve this?
as far understand looking way generate short, unique, alphanumeric identifiers documents. kind of thing url shorteners (see questions making short url similar tinyurl.com or what's best way create short hash, similiar tiny url does? or how make unique short url python?, etc.). answer based on assumption.
the datastore generates unique auto-incremented ids can rely on that. multiple data centers not problem, ids unique, short (at least, initially) , there no collision. how tinyurl , similar services accomplish it.
you can request 1 or more unique ids before persist new document in datastore using datastoreservice.allocateids(), example:
keyrange keyrange = dataservice.allocateids("mydocumentmodel", 1); long uniqueid = keyrange.getstart().getid();
you can "hash" id or shorter alphanumeric id transcoding integer id base64 (or base36 or other base define own characters, e.g., omitting vowels can avoid generating obvious swear words accidentally).
if predictability issue can prefix/suffix alphanumeric id random characters.
Comments
Post a Comment