I. Introduction to Redis

Redis, or Remote Dictionary Server, is a completely memory-based key-value storage database. It is currently the preferred caching middleware of major companies. Let’s take a look at the diagram below to see how Redis is used in mainstream architectures.

The cache layer middleware of choice in the figure above is Redis. When some storage information that does not change often is loaded into the cache, the client first checks the cache when requesting the data and returns the data directly. This step greatly relieves the storage pressure of the storage layer. If the data is deleted from the cache, then a penetrating query is carried out to store the obtained data through the cache layer, write the obtained data back to the cache layer, and then return the data. In addition, the cache layer can also be used for fusing. When the storage layer goes down, the system can cut traffic to the cache layer and make the service available. When it comes to Redis, Memcache is often compared. Memcache’s code hierarchy is similar to Hash

  • Simple data types are supported
  • Persistent storage of data is not supported
  • Master/slave architecture is not supported
  • Sharding is not supported

Sharding: A large amount of data is broken and distributed on multiple physical machines according to certain routing rules

Consider the advantages of Redis

  • The data types supported are very rich
  • Supports persistent storage on data disks
  • Support the master-slave
  • Support the shard

The Redis QPS is 100000+ (QPS = Query Per Second).

  • Because it’s completely memory based, the vast majority of requests are purely memory operations — very efficient
  • The time complexity of data structure query is basically O(1), and the operation of data is also simple
  • It uses a single thread, a single thread can also handle high concurrency requests, want to multi-core can also start multi-instance
  • It uses a multiplex I/O multiplexing model, that is, non-blocking I/O

The single thread of Redis means that its internal main thread is single threaded, which includes the processing of I/O events and related requests corresponding to I/O. The main thread also contains the processing of expired key/value pairs. The single thread of Redis enables the system to write Redis without frequent context switching and other operations in the case of multiple instance nodes, so its efficiency is very high. Note that this single thread does not mean that the entire Redis Server is single threaded. Single-threaded here is single-threaded only for handling I/O events. Like persistence, Redis Server uses child processes or child threads to persist operations.

The multiplex I/O multiplexing model mentioned above can be seen in this article

Redis common data types

3. How to query a fixed prefix key from mass data

How to realize distributed lock

How to use Redis to achieve asynchronous queue

6. Redis persistence mode

Pipeline and master-slave synchronization

Redis cluster

1. How to expand capacity based on common data types?