Meditations on programming, startups, and technology
New Relic

Introducing Redis: a fast key-value database

RedisOne of the many advantages of having remarkable friends is learning quite early on about their most ambitious and interesting projects. Today, I’m going to talk about Redis, one such project that my friend Salvatore “antirez” Sanfilippo started.

Redis (REmote DIctionary Server) is a key-value database written in C. It can be used like memcached, in front of a traditional database, or on its own thanks to the fact that the in-memory datasets are not volatile but instead persisted on disk. As such it’s also very similar to memcachedb, though unlike the latter, Redis provides you with the ability to define keys that are more than mere strings (as well as being able to handle multiple databases). At this early stage (beta 6), lists, sets and even basic master-slave replication are supported, but more features are in the works (including compression).

Despite being a very young project, it already has client libraries for several languages: Python and PHP (by my friend Ludovico Magnocavallo), Erlang (by my friend Valentino Volonghi of Adroll.com), and Ruby by Ezra Zygmuntowicz. Except for Ezra, who should no doubt be a familiar name to most, Redis is pretty much an Italian product; and like other Italian products such as Lamborghini and Ferrari, this schema-less database is amazingly fast.

On an entry level Linux box, Redis has been benchmarked performing 110,000 SET operations, and 81,000 GETs, per second. As you can imagine, fast performance is one of the major goals of this project, and having chosen linked lists to have at the core of Redis’ implementation allows it to perform PUSH operations in O(1).

Salvatore has implemented a Twitter clone known as Retwis to showcase how you can use Redis and PHP to build applications without the need for a database like MySQL or any SQL query. He used PHP in order to reach a wide audience, but of course you can do the same with Python, Ruby or Erlang. The remarkable thing is how fast this clone is. According to Apache’s benchmark data, Salvatore’s commodity server (a Pentium D which is also running several large sites) could handle 150 pageviews per second (6 milliseconds each) for each of the 50 concurrent users. This was possible while using the grand total of 1 MB of RAM for the database. Of course, this is just a quick benchmark and there wasn’t a huge deal of data in the database either, but the responsiveness was very impressive nevertheless.

Salvatore will be publishing a beginner’s article based on the PHP Twitter clone he wrote, soon. It should appear on this wiki page where the code is already available, within the next couple of days. You can follow Salvatore and the evolutions of this project through his Twitter account. So check Redis out and (especially if you have experience with key-value databases) don’t forget to provide your feedback and/or contribute to the project.


If you enjoyed this post, then make sure you subscribe to my Newsletter and/or Feed.

receive my posts by email

13 Responses to “Introducing Redis: a fast key-value database”

  1. ludo says:

    As fast as a Ferrari, as easy to digest as a pizza :)

  2. Alexis says:

    Thanks for telling about the project.

    Is there any kind of query language support or one can only get value by a key?

  3. antirez says:

    Alexis: hello, there is no query language but you can do more than asking for the value of a key. For example the “KEYS pattern” command will return all they keys matching a given pattern. LRANGE will return a range of a list, and SINTER will return the intersection between Set values stored at two or more keys and so on.

    I’m working on ways to allow sorting right now.

  4. [...] Introducing Redis: a fast key-value database Currently / Submitted 4 seconds ago by jsuggs Tags: databases! technology! Redis (REmote DIctionary Server) is a key-value database written in C. It can be used like memcached, in front of a traditional database, or on its own thanks to the fact that the in-memory datasets are not volatile but instead persisted on disk. As such it’s also very similar to memcachedb, though unlike the latter, Redis provides you with the ability to define keys that are more than mere strings (as well as being able to handle multiple databases). At this early stage (beta 6), lists, sets and even basic master-slave replication are supported, but more features are in the works (including compression). [...]

  5. José Valim says:

    Antonio, thanks for sharing! :)

    When I get a project that I’ll need to use a key-value store, it will be the hardest decision ever: Tokyo-cabinet, scalaris, CouchDB, Dynomite, Ringo and now Redis. And of course, this is just for start.

  6. [...] March 11, 2009 Antonio Cangiano wrote: [...]

  7. [...] Salvatore Sanfilippo es el creador de este peculiar sistema de base de datos y para demostrar sus bondades ha creado un clon de Twitter utilizando PHP y reemplazando MySQL por su Redis. El proyecto se llama Retwis y pronto lanzará una artículo detallando el proceso de creación y desarrollo de la misma. [...]

  8. Riccardo says:

    Awesome! :)
    Will definitely have a serious play with it.

    Thanks for “broadcasting” these news, Italian achievements too often fall out of my poor radar :-/

  9. Yuri Baburov says:

    Wow, you reinvented Berkeley DB? Cool!

  10. taelor says:

    How does in come into play with moneta?

  11. [...] So far I’ve been quite pleased with Redis, especially given how new it is. It’s quite fast, is network accessible, atomic operations make locking unnecessary, supports sortable and sliceable [...]

  12. AnxiousAnnie says:

    BerkeleyDB lives on harddisks, Redis lives in the memory. Quite a difference.

  13. crazy says:

    Thanks for “broadcasting” these news, Italian achievements too often fall out of my poor radar :-)

  14. Dizi izle says:

    Alexis: hello, there is no query language but you can do more than asking for the value of a key. For example the “KEYS pattern” command will return all they keys matching a given pattern. LRANGE will return a range of a list, and SINTER will return the intersection between Set values stored at two or more keys and so on.

    I’m working on ways to allow sorting right now.

  15. dizi izle says:

    How does in come into play with moneta ..thanks

  16. sikis says:

    t’s quite fast, is network accessible, atomic operations make locking unnecessary,

  17. dizi seyret says:

    Thanks for telling about the project.

Leave a Reply

I sincerely welcome and appreciate your comments, whether in agreement or dissenting with my article. However, trolling will not be tolerated. Comments are automatically closed 15 days after the publication of each article.

Current ye@r *

Copyright © 2005-2014 Antonio Cangiano. All rights reserved.