Redis can be used in innumerable ways, however there are a number of patterns that are employed to solve frequent problems. We’ve gathered a collection of common patterns that we deem as best practices for solving these problems. This collection is not exhaustive nor does it represent the only ways to use Redis, but rather we hope it will serve as a first-stop when approaching a problem to be solved with Redis.
In this best practices guide, we have divided it into over-arching 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.
- With “Communication Patterns” the focus is on Redis patterns that move data around a system. In this way, 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 both the uses of the probabilistic data structure and 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.
- Finally, 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 and intentionally lack any language-specific implementation details. This reflects the diversity of Redis users and prevents needless exposition regarding syntax or linguistic structures.