Redis introduction and usage scenario explanation
This article mainly introduces the introduction and usage scenarios of redis. Xiaobian thinks it's very good. Now I'll share it with you and give you a reference. Let's follow Xiaobian and have a look
(1) Disadvantages of persistent databases
The relational databases we usually use include mysql, Oracle and sqlserver. In the process of development, the data is usually linked to the database through the database driver provided by the web for addition, deletion, modification and query.
So, where are the data stored in our daily database? Let's take MySQL as an example. Open the data folder under the folder directory where MySQL is located, as shown below:
We can find that there are all databases created by us. Open one of them and you can see the tables created by us. They exist in the form of files (format frm and IBD):
In other words, all the data in the relational data we use everyday are stored in the hard disk of the machine where we deploy the database.
Generally, after the development of our website is completed and online, the reading and writing efficiency of the server is an important condition for the running speed of the website. Of course, there is also the bandwidth of the server, but these things can be solved by updating and upgrading the hardware. In fact, the thing closely related to the operation efficiency of the website is our database.
The speed of database processing data is closely related to the speed of website, and data query, data processing and so on are related to the speed of database processing. One of the solutions to improve the data processing capacity of the database is the optimization technology of SQL statements. The processing efficiency of SQL statements is relatively high, the database processing capacity will go up, and the data processing capacity of the website will be faster.
However, when the processing and access volume of the website is very large, the pressure on our database becomes greater. The connection pool of the database and the ability of the database to process data at the same time will be greatly challenged. Once the database bears its maximum bearing capacity, the data processing efficiency of the website will be greatly reduced. At this time, we need to use high concurrency processing, load balancing and distributed database, which cost both manpower and money.
If our website is not a very large website, and we want to improve the efficiency of the website and reduce the number of reads and writes to the database, we need to introduce caching technology.
(2) Cache
Cache is the backup of data stored in memory. When the data has not changed in essence, we will not let the data query go to the database for operation, but go to the memory to get the data, which greatly reduces the number of reads and writes of the database, and the speed of reading data from memory is faster than that of querying the database, which improves the efficiency at the same time.
Use caching to reduce the load on the database:
When developing a website, if some data will not change in a short time, and they will be accessed frequently, in order to improve the user's request speed and reduce the load of the website, put these data on a medium with faster reading speed (or obtain the data through less computation). This behavior is called caching the data. The media can be file / database / memory. Memory is often used for database caching.
There are two forms of caching:
Page cache is often used in CMS (content management system) memory management system. Data cache is often used in the specific data of the page.
There are two types of caching:
Page caching (smart static technology)
Data cache
(3) Redis introduction
A caching technology we need to learn is redis:
Redis is the abbreviation of remote dictionary server (remote data service). It is a memory cache database developed by Italian antirez (Salvatore Sanfilippo). The software is written in C language and its data model is key value. It supports rich data structures (types), such as string / list / hash / set / sorted set.
Persistent (backup a copy of the data to the hard disk while running to prevent data loss caused by power failure. After the power failure is restored, redis will restore the data in the hard disk to the memory) to ensure the safety of the data.
4) Comparison between redis and Memcache
1. Redis not only supports simple K / V data, but also provides storage of list, set, Zset, hash and other data structures.
2. Redis supports master-slave mode applications.
3. Redis supports data persistence. It can keep the data in memory on disk and can be loaded again for use when restarting
4. The maximum limit for a single value in redis is 1GB, and memcached can only store 1MB of data.
The above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.