Why I Like

Why I like Redis

Or, Redis: my favorite little key-value store

I really like Redis. I mean, really like Redis. From the site:

> Redis is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

They don’t mention that it is also fast, in-memory (with to-disk journaling if needed) and awesome. I first had occasion to use it as a caching mechanism for user searches, and fell in love with it right away. It’s flexible (like the marketing blurb says, a key can be almost anything), and the command set is pretty straightforward. Plus, if you’re confused about something or just want to take Redis for a test-drive, you can try out most of the commands live on the website.

Some of the features I like the most (note that this is not a comparison between key-value stores; I’ve honestly not done a comprehensive study. Just some things I like about Redis that may or may not be available elsewhere):

  • You can set a TTL on any key. This was the feature that made me look to Redis for caching; you can tell any value that you set to expire in n seconds, and it will expire in n seconds without any more input from you. You can even add TTL to an existing key, if you’d like.
  • Atomic value incrementing. I have nightmares of high-load applications using non-atomic incrementing for object identity. With Redis, INCR not only increments the value, but returns the new value as part of the operation.
  • In-memory store. This feature means that Redis is not the right choice for 100% of use cases (if your intended dataset is larger than your available RAM, you have a problem), but that’s fine. The entire dataset is stored in memory, which means that both read and write operations are really fast (plus or minus network latency, of course).

I know it’s a short list, but Redis has entrenched itself firmly in the set of go-to tools I use for my development stack. I’ve used it for caching, and I’m quite interested to see what other uses it will be a good fit for. I’m thinking job queue.

Leave a Reply