Redis is the most popular in-memory key-value data store. It is very lightweight and its
data types give it an edge over other competitors. If you need an in-memory database
or a high-performance cache system that is simple to use and highly scalable, Redis is
what you should use.
This book is a fast-paced guide that teaches you the fundamentals of data types,
explains how to manage data through commands, and shares experiences from
big players in the industry.
What this book covers
Chapter 1, Getting Started (The Baby Steps), shows you how to install Redis and
how to use redis-cli, the default Redis command-line interface. It also shows
you how to install Node.js and goes through a quick JavaScript syntax reference.
The String, List, and Hash data types are covered in detail, along with examples
of redis-cli and Node.js.
Chapter 2, Advanced Data Types (Earning a Black Belt), is a continuation of the
previous chapter. It presents the Set, Sorted Set, Bitmap, and HyperLogLog data
types. All the examples here are implemented with redis-cli and Node.js.
Chapter 3, Time Series (A Collection of Observations), uses all of the knowledge of
data types from the previous chapters to build a time series library in Node.js. The
examples are incremental; the library is initially implemented using the String data
type, and then the solution is improved and optimized by using the Hash data type.
Uniqueness support is added to the String and Hash implementations by using the
Sorted Set and HyperLogLog data types, respectively.
Preface
[ viii ]
Chapter 4, Commands (Where the Wild Things Are), introduces Pub/Sub, transactions, and
pipelines. It also introduces the scripting mechanism, which uses the Lua programming
language to extend Redis. A quick Lua syntax reference is also presented. A great
variety of Redis commands are presented in this chapter, including the administration
commands and data type commands that were not covered in the previous chapters.
This chapter also shows you how to change Redis's configuration to optimize different
data types for memory or performance.
Chapter 5, Clients for Your Favorite Language (Become a Redis Polyglot), shows how to
use Redis with PHP, Python, and Ruby. This chapter highlights the features that
vary more frequently with clients in different languages: blocking commands,
transactions, pipelines, and scripting.
Chapter 6, Common Pitfalls (Avoiding Traps), illustrates some common mistakes
when using Redis in a production environment and related stories from real-world
companies. The pitfalls in this chapter include using the wrong data type for a given
problem, using too much swap space, and using inefficient backup strategies.
Chapter 7, Security Techniques (Guard Your Data), shows how to set up basic security
with Redis, disable and obfuscate commands, protect Redis with firewall rules, and
use client-to-server SSL encryption with stunnel.
Chapter 8, Scaling Redis (Beyond a Single Instance), introduces RDB and AOF
persistence, replication via Redis slaves, and different methods of partitioning
data across different hosts. This chapter also shows how to use twemproxy to
distribute Redis data across different instances transparently.
Chapter 9, Redis Cluster and Redis Sentinel (Collective Intelligence), demonstrates the
differences between Redis Cluster and Redis Sentinel, their goals, and how they
fit into the CAP theorem. It also shows how to set up both Sentinel and Cluster,
their configurations, and what happens in different failure scenarios. Redis Cluster
is covered in more detail, since it is more complex and has different tools for
managing a cluster of instances. Cluster administration is explained via native
Redis commands and the redis-trib tool.