Home> Database> Redis> body text

redis note recording-overview

Release: 2023-08-08 16:24:05
forward
1170 people have browsed it

Introduction to redis

Redis is an open source (BSD licensed), in-memory data structure server that can be used as a database, cache and message queue broker . It supportsString,Hash table,List,Set,Ordered Set,bitmap,hyperloglogsand other data types . Built-in replication,Lua script, LRU eviction,transactionand different levels of disks The persistence function also provides high availability through Redis Sentinel and automaticpartitioningthrough Redis Cluster.

How fast is Redis

Redis is based on memory and uses a single processSingle-threadedmodel'sKV database,is written in C language, the official data provided can reach 100,000 QPS (number of queries per second).

redis note recording-overview

The horizontal axis is the number of connections, and the vertical axis is QPS.

We looked at the official data and found that it is really fast; as a programmer with dreams, we must know why it is so fast, you are right wrong!

Then I checked some information on the web page, and the general situation is as follows:

  • Completely based on memory, most of them are Some requests are purely memory operations and are 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);

  • The data structure is simple, and it is Data operations are also simple. The data structure in Redis is specially designed;

  • adopts a single thread to avoid unnecessary context switching and competition conditions, and also There is no CPU consumption due to switching caused by multi-process or multi-thread, there is no need to consider various lock issues, there is no locking and releasing lock operations, and there is no performance consumption caused by possible deadlocks;

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

  • Use the underlying model differently. The underlying implementation method and the application protocol for communication with the client are different. Redis directly builds its own VM mechanism, because if the general system calls system functions, it will waste a certain amount of time to move and request;

The multi-channel I/O multiplexing model uses select, poll, and epoll to monitor the I/O events of multiple streams at the same time. When idle, the current thread Blocked, when one or more streams have I/O events, they will wake up from the blocking state, so the program will poll all streams (epoll only polls those streams that actually emitted events), and Only ready streams are processed sequentially, which avoids a large number of useless operations.

To sum up, there are actually three points:

  1. Use the epoll network model and use a single thread to process requests.

  2. #Use various high-performance data structures that meet your needs.

  3. #redis uses memory operations; and is written in C language.

Starting point

This series of articles does not focus on discussing the epoll network model, but mainly records the process of learning the redis data structure principle. Let us know why redis data processing is very fast.

  1. The string implementation principle of redis

  2. The list implementation principle of redis

  3. Redis's set implementation principle

  4. redis's sorted set implementation principle

  5. Redis hash implementation principle

  6. Introduction to other data types

The above is the detailed content of redis note recording-overview. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:Golang菜鸟
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!