High Performance URL-Shortening with Redis-backed nginx

I've spent my vacation wisely on writing my new customer interface. While doing that, i've played a lot with redis which is one of the most remarkable pieces of software i've ever seen. Altho it's not usable for "important"/"non-temporary" data (since it's only a key value storage and has limited query capabilities), it's perfectly made for caching stuff.

One example is my PostgreSQL IP traffic accounting. Works nifty neat, i can get results for any subnets in 0.055 seconds. Since that data only changes once every 15 minutes, i cached it and sliced the query time down to less than 0.017s. The sample query i use covers my whole /20 prefix.

How about some config

To setup the shortening guide, we need the following components:

If you don't know what git is or how to use it, you shouldn't try this.. you've got bigger things to worry about.

Add those to your nginx's ./configure and start compiling:

While compiling, we configure and startup redis. These are values you should take a look at:

Please note that appendonly no will disable persistence whatsoever. Your data will be fucked.

The final part is to get nginx to redirect to the redis response. That's quite easy:

My regexp adds the special websauce which removes redis return-value formed like "$34\r\nyourvalue".

Now write a fancy plugin or whatever to populate your links.

Best regards!

Flattr me!

Tell your friends!