Redis rocks!

In my development blog, I previously wrote that MongoDB was the future of database storage. I might reconsider my decision, now that I've discovered Redis. In a nutshell, Redis is a key-value store. But it's not a simple key-value database, as it has lots of commands and extra goodies, such as file persistence (so data can be stored from memory to a file, and restored in case of failure) and awesome data structures like lists (with push / pop) and sets (even ordered sets). Besides that, Redis boasts atomicity and even master-slave replication. It's quite a lot of stuff for a lean package.

One of the things I love the most about Redis is it's speed. Believe me, this little database is fast. Redis includes a benchmark tool, so I ran the default benchmark (Approximately 10,000 total requests per command, from 50 simultaneous clients) just to demonstrate its raw speed. These tests were run on a Mac Mini (1.83 GHz Intel Core 2 Duo, 2 GB RAM) under Ubuntu 9.10 Server:


[email protected]:~$ redis-benchmark ====== SET ====== 10005 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1
34.89% <= 0 milliseconds 99.19% <= 1 milliseconds 100.00% <= 2 milliseconds 74111.11 requests per second
====== GET ====== 10003 requests completed in 0.13 seconds 50 parallel clients 3 bytes payload keep alive: 1
34.62% <= 0 milliseconds 99.79% <= 1 milliseconds 99.83% <= 2 milliseconds 99.87% <= 3 milliseconds 99.91% <= 4 milliseconds 99.94% <= 5 milliseconds 99.97% <= 6 milliseconds 99.99% <= 7 milliseconds 100.00% <= 8 milliseconds 74649.25 requests per second
====== INCR ====== 10005 requests completed in 0.15 seconds 50 parallel clients 3 bytes payload keep alive: 1
25.60% <= 0 milliseconds 99.73% <= 1 milliseconds 99.80% <= 2 milliseconds 99.83% <= 3 milliseconds 99.86% <= 4 milliseconds 99.89% <= 5 milliseconds 99.92% <= 6 milliseconds 99.95% <= 7 milliseconds 99.97% <= 8 milliseconds 100.00% <= 9 milliseconds 65392.16 requests per second
====== LPUSH ====== 10001 requests completed in 0.13 seconds 50 parallel clients 3 bytes payload keep alive: 1
37.62% <= 0 milliseconds 99.78% <= 1 milliseconds 99.82% <= 2 milliseconds 99.86% <= 3 milliseconds 99.89% <= 4 milliseconds 99.93% <= 5 milliseconds 99.96% <= 6 milliseconds 99.99% <= 7 milliseconds 100.00% <= 8 milliseconds 77527.13 requests per second
====== LPOP ====== 10000 requests completed in 0.14 seconds 50 parallel clients 3 bytes payload keep alive: 1
34.13% <= 0 milliseconds 99.69% <= 1 milliseconds 99.82% <= 2 milliseconds 99.86% <= 3 milliseconds 99.90% <= 4 milliseconds 99.93% <= 5 milliseconds 99.96% <= 6 milliseconds 99.98% <= 7 milliseconds 100.00% <= 8 milliseconds 74074.07 requests per second
====== PING ====== 10000 requests completed in 0.12 seconds 50 parallel clients 3 bytes payload keep alive: 1
43.79% <= 0 milliseconds 99.80% <= 1 milliseconds 99.85% <= 2 milliseconds 99.89% <= 3 milliseconds 99.91% <= 4 milliseconds 99.93% <= 5 milliseconds 99.97% <= 6 milliseconds 100.00% <= 7 milliseconds 86206.90 requests per second

Yeah, you read that right. On this somewhat low-end computer (by today's standards), Redis still manages to do over 74,000 SET (write) and GET (read) operations per second. Push and pop list operations also do well over 70,000 requests. On bigger hardware, expect these numbers to be much higher. Besides speed, I've also been impressed by the stability of Redis. I've been running Redis non-stop on the Mac Mini for over two weeks, and I've never had a single issue with it.

I got really interested in Redis after Defunkt (of GitHub fame) open-sourced Hurl. Hurl was an entry in this year's Rails Rumble competition. I used it quite extensively when developing with PayPal's APIs. After it was released, I noticed that Hurl used Redis for persistence. I was kind of puzzled why a key-store value was used for this. However, Defunkt wrote an excellent post mostly explaining the SORT operation, but also included some additional details on how Redis was used in Hurl. It made the decision to use Redis clear. Well, I'm also willing to bet that he used Redis because us programmers love to use the new hotness.

I feel that Redis will be something big soon. There are a few open-source projects using it, including the aforementioned Hurl and Resque. I already have a few ideas where I can use some of this functionality for current sites that I'm working on (such as simple counters, or a tag-like system where we can push and pop tags from a list). Check Redis out if you need some quick and simple storage.

Written by

Dennis Martinez

Show Comments