Home  >  Article  >  Database  >  Why is redis so fast

Why is redis so fast

藏色散人
藏色散人Original
2019-06-10 10:52:432704browse

Redis is a K-K memory database written in ANSI C language, with excellent performance, network support, and persistence, and provides APIs in multiple languages. Its commonly used types are mainly String, List, Hash, Set, and ZSet.

Why is redis so fast

Why is redis so fast?

1. Completely based on memory, most requests are pure memory operations, very fast. The data is stored in memory, similar to HashMap. The advantage of HashMap is that the time complexity of search and operation is O(1);

2. The data structure is simple, and the data operation is also simple. The data structure in Redis It is specially designed;

3. It uses a single thread to avoid unnecessary context switching and competition conditions. There is no switching caused by multi-process or multi-threading to consume the CPU, and there is no need to consider various locks. There is no problem of locking and releasing locks, and there is no performance consumption caused by possible deadlocks;

4. Use multi-channel I/O multiplexing model, non-blocking IO;

5. The underlying models used are different, the underlying implementation methods and the application protocols for communication with the client are different. Redis directly builds the VM mechanism by itself, because if the general system calls system functions, it will waste a certain amount of time. Move and request;

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.

For more Redis technical articles, please visit the redis usage tutorial column!

The above is the detailed content of Why is redis so fast. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is redis?Next article:What is redis?