Closed technoweenie closed 12 years ago
In Ruby 1.8.x, pack fails if the value is too large - but you can get the same behaviour by only considering the low order bits, by changing
[Digest::MD5.hexdigest(url).to_i(16)].pack("N")
to
[Digest::MD5.hexdigest(url).to_i(16) % 2**32].pack("N")
This does not get you the unique incrementing ID behaviour, but you do at least get behaviour that agrees with the current behaviour in 1.9
Use the length/charset options. I have some ideas on refactoring the shortener code so you could plug your own scheme in if needed.
I'd really like DBs with auto increment counters to use that somehow. That might have to be 2 queries though (one to insert and get the ID, and another to set the code).
It has to do with the url shorten code:
The most common url shortening algorithms involve mapping a unique incrementing ID to some custom encoding:
http://stackoverflow.com/questions/742013/how-to-code-a-url-shortener
Riak has no way to get this though. I have some thoughts on doing host-based counters, but it's way out of scope. Maybe if someone gets really bored...