A Quick Redis Key-Value Example for the Holidays
Source: http://www.christmas-graphics-plus.com/free/present-clip-art.html
I really like Mongo, and we adopted it at my former company in large part because it gave us full NoSQL goodness without taking anyone too far out of the SQL-Active Record world we Railsians have come to know and love.
For my final little example for the holidays, I'd like to go outside the SQL-box, and present an example in NoSQL for which NoSQL fits like a glove, and SQL just doesn't make sense. I'll set up and use the Redis NoSQL data store because key-value pairings are just what I need.
The example application here is a URL-shortener. URL-shorteners map a short, meaningless text string with a (sometimes frightfully) longer URL, and might have been a curiosity in a Twitterless world, but are vital in a tweety world where 140-chars-is-all-you-get!
The good news is, we've already got our base image, and adding a new Redis data store and example app to it only took about an hour. As before, you can play with the URL-shortener at Redis URL Shortener, and you can download and play with the code for the application at
Redis URL Shortener Source Code.
Here the great work was done by Christoph Petschnig, who wrote the original app and posted it to github -- my contributions are limited to updating it to Rails 3.0.3, moving it to AWS and giving it some CSS formatting.
All the same, this is a great example of where you'll want a NoSQL solution and just why such a solution matters. URL-shortening is a perfect application for key-value pair databases, because all you have are the key (the hash the app produces), and the value (the original URL), and you'll want to be able to make zillions of them, and make them lickety-split.
Redis is perfect for that. It's available (BSD-licensed), written in C/C++, and generally said to be wicked-fast. Redis can do transactions, and was designed to be a disk-backed in-memory database. It may not fit every need, but it's perfect for a pure key-value application like URL-shortening.
Mini_url is yet another "toy" application, but you can get it running quickly, and on the cloud. To try it out with real application loads you need only a little programming time and a willing community to try it or a pile of data to feed it.
"Hello World" matters -- if you can say it, you might get the world to answer "Hello!" back.
Happy New Year!