For more best practices and definitions of related terms, view the Redis glossary.
Introduction
Redis can be used in innumerable ways, however there are a number of patterns that are often employed to solve frequent problems. We’ve gathered a collection of common patterns that we deem best practices for solving these problems. This collection is not exhaustive nor does it represent the only ways to use Redis, but we hope it will serve as a first step when approaching a problem to be solved with Redis.
This best-practices guide is divided into multiple sections and sub-sections as necessary:
- In the “Indexing Patterns” section we cover ways to go beyond key-value access with Redis. This includes ways to smartly use both specific keyspace patterns and the different structures in Redis to aid not only in finding data in your database, but to reduce access complexity.
- In “Communication Patterns,” the focus is on Redis patterns that move data around a system. In this situation, Redis is not acting as a storage engine but rather a pathway of data.
- “Data Storage Patterns” describes methods to store more complex data in Redis. We evaluate complex document scenarios that can be generalized in simple or complex ways.
- Patterns concerning temporally related data are covered in the “Time-Series Pattern” section.
- Rate limiting is a common use for Redis, in the “Basic Rate-Limiting Pattern” section, we go over the fundamentals of this use case.
- Bloom filters have long been associated with Redis and in the “Bloom-Filter Pattern” section we cover the uses of the probabilistic data structure as well as how they differ from non-probabilistic counterparts.
- “Counting” is a surprisingly deep subject. In this section, we explore how to count activity and unique items in space and computationally efficient ways.
- DevOps or Site Reliability Engineer responsible for Redis? Here are the Observability best practices you should be aware of.
- Finally, in “Lua Helpers,” we talk about some of the ways that Lua can be pressed into service to make Redis do more with less.
This guide is non-linear, so if you’re trying to find out more, you can start anywhere. Otherwise, you can use the navigation tree to find topics that are most relevant to you.
A note on the lack of source code: Wherever possible, these collections are presented in simple commands with logic/flow descriptions only. They intentionally lack any language-specific implementation details. This reflects the diversity of Redis users and prevents needless exposition regarding syntax or linguistic structures.