This is the second day of my participation in the November Gwen Challenge. Check out the details: the last Gwen Challenge 2021
See 👉 speed
- Recently followed the B station video to see the introduction to REDis, for the pure theoretical knowledge of Redis has a preliminary understanding, this column will first update the introduction, and then there will be project combat (applied in small programs or other projects above), welcome to pay attention to this column to study together!
💫 refer to the syllabus
This column will combine the two courses of Silicon Valley and Crazy God theory, and basically cover the knowledge points including but not limited to those in the diagram.
NoSQL
NoSQL(NoSQL = Not Only SQL), meaning “more than SQL”, refers to non-relational database. NoSQL is stored in a simple key-value mode rather than in business logic. Therefore, the expansion capacity of the database is greatly increased.
- Does not follow the SQL standard.
- ACID is not supported.
- Far outperforms SQL performance.
Applicable scenario
- High concurrent reads and writes to data
- Read and write massive data
- Highly scalable to data
Not applicable Scenario
- Transaction support required
- SQL – based structured query storage, dealing with complex relationships, need to be ad-hoc query.
- In cases where SQL is not required and cannot be used, consider using NoSql
An overview of the
Redis (Remote Dictionary Server) Is an open source, network-enabled, memory-based and persistent logging, key-value database written in ANSI C, with multiple language apis.
- Redis periodically writes the updated data to disk or the modified operation to the appended record file, and implements master-slave synchronization on this basis.
use
1, memory storage, persistence, memory is power is lost, so persistence is very important (RDB, AOF) 2, high efficiency, can be used for caching 3, release and subscription system 4, map information analysis 5, timer, counter (page views!)
features
1. Multiple data types 2. Persistence 3. Cluster 4
Historical development
At first, the amount of data is very small, and only a single table is required to handle reads and writes
In the 90’s, a basic website visit is usually not too much, a single database is quite enough! At that time, the more static pages to use Html ~ the server is not too much pressure at all! Think about this situation: What is the bottleneck of the entire site? 1, if the amount of data is too large, a machine can not put! 2, data index (B+ Tree), a machine memory can not put 3, traffic (read and write mixed), a server can not bear
Memcached + MySQL + vertical split
If one server is responsible for writing, how to synchronize to the front server to read?
Caching also solves the problem of reads
Website 80% of the situation is reading, every time to query the database is very troublesome! So if we want to reduce the pressure of data, we can use caching to ensure efficiency!
Development process: Optimized data structure and indexing –> File caching (IO) –> Memcached (the hottest technology of the time!)
MySQL cluster + horizontal split
The read volume is not written to mysql in real time. It is written to the cache first and then written to mysql at a certain time
MyISAM: table lock, very affect efficiency! High concurrency can lead to serious locking problems
Switch to Innodb: row locking
Slowly began to use sub – database sub – table to solve the pressure of writing! MySQL introduced table partitioning in what era! Not many companies use this!
MySQL cluster, well meet all the needs of the era!
The Linux version installed
1. Download the installation package from the official website! 2, unzip the Redis installation package to your desired directory!
tar -zxvf
3. Installation of basic environment
yum install gcc-c++
4. Go to the decompressed directory
make
4. Go to the SRC directory
make install
- If you have any problems here, you can search for relevant installation tutorials and download Windows or Linux versions according to your needs
Redis running
Set daemonize no to yes to enable background startup
Conf (128 lines) file and change daemonize no to yes to start the service in the background
Protected-mode set to no
The default is set to yes, preventing remote access, after Redis3.2.3
Find # requirePass Foobared
Remove the # comment and change foobared to your password or requirepass to your password in a separate line
- Must set the password ah, was hacked into the server by redis, implanted dig antivirus hemp 🙊(details see boiling point)
Note that you select conf!!!!! when starting the server
./redis-server .. /redis.conf
Select conf here to start
/redis-cli -p Port number
Server connection
After entering auth you set the password
The operation is successful only after the verification succeeds
Redis closes and exits
SHUTDOWN
- Then the exit
Performance analysis
Redis-benchmark is a stress test tool! Official performance testing tools! Redis-benchmark command parameter!Let’s take a quick test:How do you look at these analyses?
Basic knowledge of
Default 16 databases, can be switched with SELECT
Redis is fast, official said, Redis is based on memory operation, CPU is not Redis performance bottleneck, Redis bottleneck is based on the machine’s memory and network bandwidth, since you can use a single thread to achieve, use a single thread!
Redis is written in C language, and the official data provided is 100000+ QPS, not worse than Memecache which also uses key-vale!
Why is Redis single thread so fast?
Myth 1: A high-performance server must be multithreaded? Myth 2: Multithreading (CPU context switches!) Must be more efficient than a single thread! Core: Redis is to put all the data in memory, so using a single thread to operate is the most efficient, multithreading (CPU context will switch: time-consuming operation!!) For memory systems, it is most efficient if there is no context switch! Multiple reads and writes are all on the same CPU. In memory, this is the best solution!
💠 Next post
- In the next part, we will introduce the common data types and related commands in Redis, and then we will analyze the redis configuration files and other related knowledge.
reference
- Silicon Valley Redis6 video
- Crazy god says Redis video