News for hackers. Stuff that matters.
Re:Show HN: link shortening API in Go by betamike on Thursday February 13, 2014 @09:50AM (#7231630)
Very cool. If you have a recent enough version of Redis, you may want to move away from doing the lookup using KEYS and move to SCAN (http://redis.io/commands/scan). KEYS will work for a while, but with a large enough DB it can become a very slow operation so it's not typically recommended for a production system.

Also, just curious, I see that the original url is encoded in the key, so the key is "<short>||<original>". Since the key is already a hash, it seems that you could eliminate having to scan over every key in Redis by making each key be only "<short>" and having an additional field in the hash for "original". Then a lookup becomes simply an HGETALL (if you need to get the "count" field, otherwise just an HGET for the "original" field). I might be missing something though! </armchair programming>

Re:Show HN: link shortening API in Go by jnye131 on Thursday February 13, 2014 @10:23AM (#7231786)
By encoding the original URL in the key you can look up to see if a URL has been shortened already, and serve that.

Thanks for the info re scan I'll have a look and check my version of redis.

[deleted]
Re:Show HN: link shortening API in Go by jnye131 on Thursday February 13, 2014 @10:57AM (#7232005)
Good point, I'll make a ticket on the git hub so I don't forget.