#redis is a non-relational in-memory database. Data is stored in memory, and memory reading speed is very fast. If it is just a simple key-value, memory is not the bottleneck. Generally, hash searches can reach the order of millions of times per second. (Recommended learning: Redis Video Tutorial)
Using a single thread to avoid unnecessary context switching and race conditions
The internal implementation uses epoll , using a simple event framework implemented by epoll itself. Read, write, close, and connect in epoll are all converted into events, and then use the multiplexing feature of epoll to never waste any time on io
Because Redis operations are very fast— —All its data is in memory, and there is no need to access the disk at all. As for concurrency, Redis uses multi-channel I/O multiplexing technology, and its own concurrency efficiency is not a problem.
Of course, a single Redis process cannot use multiple cores (it can only run on one CPU core at any time), but it is not a very computationally intensive service. If the single-core performance is not enough, you can open several more processes.
Redis adopts a single-threaded model to ensure the atomicity of each operation and reduce thread context switching and competition.
In addition, the data structure also helps a lot. Redis uses hash structure throughout the process, which has fast reading speed. There are also some special data structures that optimize data storage, such as compressed tables, Compress and store short data, another example is jump tables, and use ordered data structures to speed up reading.
Another point is that Redis uses its own event separator, which is relatively efficient. It uses a non-blocking execution method internally and has a relatively large throughput capacity.
string type, binary safe
hash type, is a collection of key-value pairs
The bottom layer of the List list is a linked list
set collection No need to implement
zset sort set ordered set through hashtale
For more Redis-related technical articles, please visit the Redis database usage tutorial column to learn!
The above is the detailed content of Why redis has good performance. For more information, please follow other related articles on the PHP Chinese website!