2 ms·
On a related note, I've been trying to figure out a way to encode MongoDB ObjectIDs ( a 24-char hex string, like `"4d82a373aeb4b69aec000001"` ) into a shorter B
by psadauskas 16y ago
On a related note, I've been trying to figure out a way to encode MongoDB ObjectIDs ( a 24-char hex string, like `"4d82a373aeb4b69aec000001"` ) into a shorter Base64 string usable in URLs (eg, `/posts/{id}` ). The problem is, it still takes a 16-char Base64 to represent the same number as a 24-char hex string, and the Base64 one is even uglier.
I've been contemplating a way to generate my own ids, similar to this, but was running into trouble on how to make sure its always generated unique, on distinct machines.
- aaronblohowiak 16y agojust use a b64uri-encoded uuid, it will be 22 characters long, but you will never run into a problem and the aesthetic quality of your random ids should never matter.
- KevBurnsJr 16y agoYes, at some point you need some sort of atomic ID generation. I'm using Riak for the key-value store and Redis's atomic incr for the ID generation. Anyone who wants to save an object into the bucket first has to get a unique ID from Redis to be rotated and base62 encoded.