A deep dive into Redis' origins, design decisions, feature set, and a look at a few potential applications.
Redis (“REmote DIctionary Service”) is an open-source (BSD-licensed) database server.
History
Data Structure Server
Key Advantages
Performance
Atomicity
Foundational Data Types
Polyglot Persistence
Client Protocol
Getting Started
Key Disadvantages
RAM
Persistence
Memory Bloat
Diving In
String Keys
Expiry
Sidenote: memcached?
Replication
Persistence
Options
Binary Dumps and In-Memory Representation
Problems
Expiry
Redis Versions Prior to 2.1.3
Redis Versions 2.1.3 and Above
More on Strings
Increment
SETNX and Locking
Lists
Sets
Sorted Sets
Hashes
Redis Transactions
Redis Virtual Memory
Limitations
Implementation Details
Publish/Subscribe
Example
Usage Examples
Caching
Nginx + Redis
Interprocess Communication
Views
Job Management
Locking
Designing with Redis
Other Resources
History
The Redis project was started in early 2009 by an Italian developer named Salvatore Sanfilippo. Redis was initially written to improve the performance of LLOOGG, a real-time web analytics product out of Salvatore’s startup.
By June of 2009, Redis was stable enough, and had enough of a base feature set, to serve production traffic at LLOOGG. On June 19, 2009, an important milestone was hit:Salvatore deployed Redis to LLOOGG’s production environment and retired the MySQL installation.
Over the next months, Redis rapidly grew in popularity. Salvatore fostered a great community, added features at a very rapid pace, and dealt with any and all reports of database corruption, instability, etc. with the utmost severity.
In March of 2010 VMWare hired Salvatore to work full-time on Redis. (Redis itself remains BSD licensed.) Shortly thereafter, VMWare hired Pieter Noordhuis, a key Redis contributor, to give the project an additional momentum boost.
The rest, as they say, is history.
Data Structure Server
The most apt description of Redis is that it is a “data structure server”. This is a very natural label for the database, because Redis natively supports many of the foundational data types of computer science, and provides a rich set of familiar primitives for manipulating these types.
The supported data types are:
Strings
Lists
Sets
Sorted Sets
Hashes
Key Advantages
Performance
Redis can perform >100k+ SETs per second, and >80k+ GETs per second.
The redis-benchmark utility included with the project can be used to reproduce these findings. (More on benchmarks here and here.)
Atomicity
Every operation that Redis exposes via the available command primitives is atomic. (And, as we’ll see later, there are ways to combine multiple primitive commands into larger atomic units.) This makes application-level code easier to build and reason about.
Atomic guarantees are a direct consequence of Redis' single-threaded core; as a result, Redis' internals are simpler (no complex locking and synchronization code complicating the codebase, introducing bugs, and burning up CPU cycles).
Foundational Data Types
The data types that Redis offers are foundational. All computer scientists are very familiar with these data types and have already used them to solve countless problems.Lists, sets, etc. are more fundamental to computer scientists than relational database tables, columns, and rows.
The documentation for all Redis commands includes complexity measurements, in big O notation. This makes it very straightforward for computer scientists and software engineers to visualize, reason about, optimize, and understand the performance of Redis queries. Is it this straightforward to understand query performance in a relational database?
Polyglot Persistence
This is not specifically an advantage inherent to Redis, but is worth noting. Using Redis does not require a commitment to use it exclusively. Use Redis to solve problems that can be naturally modelled using its primitives, and embrace polyglot persistence for everything else.
Client Protocol
The client protocol is very straightforward. This makes it simple to build client libraries.
Getting Started
It is very easy to get started. Redis has no external dependencies, and getting up and running only involves the following steps:
Clone the git repository or unpack the tarball
Run make
Run ./src/redis-server
Then, from another terminal, start the interactive command line interface by running./src/redis-cli.
Feel free to issue a few commands:
redis> PING
PONG
redis> INFO
redis_version:2.1.1
...
(Alternatively, to try Redis from your browser, visit try.redis-db.com.)