In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "what is Redis cache". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Introduction what is Redis?
Redis is a storage system, which, like MongoDB, is key-value pair storage, that is, key-value structure. In other words, Redis is actually a database that can be used across platforms. This series integrates SpringBoot+Redis.
Redis itself is written in C language and is an open source system that conforms to the ANSI C standard. Redis, which stands for Remote Dictionary Server, is now commonly used in distributed databases and highly available caching systems. In fact, after learning Redis to integrate SpringBoot, it is natural to integrate SpringCloud.
Why use Redis?
Some friends may ask, since Redis and MongoDB are so much alike, why should I use the latter? why learn from the former? In fact, MongoDB and Redis are very different, they just have similarities in the way they are stored. The differences between the two are listed below:
Data storage location
The data stored in MongoDB is stored on disk, and a small part of the data is stored in memory. Why is the database data stored in memory? Because the database cache system will judge hot data, frequently accessed data should be stored in memory to achieve efficient processing.
All the data of Redis is stored in memory and written to disk regularly, which leads to the high performance of Redis. When there is not enough memory, Redis replaces the data with the LRU (Least Recently Used) algorithm, which is, yes, the operating system west replacement algorithm.
Data storage mode
MongoDB uses the mmap function to add, delete, check and modify the memory mapped by the file data. After the modification, the operating system will flush the memory data to disk. The problem is that the two are not the same transaction, so if there is a downtime between two transactions, the data will be lost naturally.
Redis has two storage modes, RDB and AOF, which we will talk about later.
Data processing speed
MongoDB is slower than Redis, which is the biggest advantage that Redis belongs to memory storage system. Of course, we don't think about the lack of memory for the time being.
In addition, at present, distributed is the mainstream technology stack of big factories, and Redis is the distributed cache method that big factories will adopt. And in dealing with scenarios with high concurrency, such as Ali Singles Day, the appearance of Tencent Games's new skin or red packets during the Spring Festival, using Redis and message queue is the mainstream method.
What is the level of entry? What is the level of proficiency?
To get started is to know nothing about Redis, but you need to have basic knowledge, such as basic data structures, basic types, basic memory knowledge, basic distributed knowledge.
Basic Java/Spring knowledge and basic operation of linux. You can rest assured that my level is mediocre, so the foundation I am talking about must be the foundation.
Proficiency does not mean that I can write a Redis by myself, or that I can become a stable developer of Redis. I can't do it myself, so the mastery here is to be able to understand the various mechanisms and algorithms of Redis, understand the common methods provided by Redis, understand Redis usage scenarios, be able to drain holes, and be able to integrate the SpringBoot framework by myself. In fact, this integrated SpringBoot framework is the simplest, and the official website is very detailed. It is best to carry out secondary development on the basis of Redis, in fact, understand the principle, can write C language, secondary development is not difficult.
Since it is a series of articles, I cannot write them all in one article, and too much content is not good for my typesetting and learner experience, so I will try my best to compress each article into an acceptable length range. I try to give links to all articles in each article for you and for me to consult in the future. If the article can help you, I hope to give you a compliment and encouragement, although it does not rely on this to survive, but it is still very happy to be recognized.
Caching and working with scenarios
What is caching?
Caching is actually a way in which a program uses memory to optimize frequently read data. The cache is part of the memory. As we wrote earlier, database operations are often stored on disk, but the IO of the disk is extremely slow, what to do? Programmers have come up with a way to make good use of memory. Is not the disk IO slow, then use memory, memory IO is very fast, but too many things, can not be put into memory how to do? Then put the commonly used data in memory.
It is now 2021, and friends familiar with NBA know that the data of Westbrook has exploded again this year, so fans may often read the data of Westbrook, and there may be a problem of high concurrency due to the fact that Westbrook has a lot of fans. But every time it is too slow to get data from disk, put Weishao's data in memory separately, and other people's data continue to lie on disk, which greatly speeds up the response speed of the system, which is called caching.
However, there is more than one star in the NBA. Curry, James and Yokic are all excellent players, and the number of fans is no less than Wei, so put all their data in the cache, so it will be soon. But we found that there are too many NBA stars to store in it. What should we do? This leads to our common cache elimination algorithm, friends who know about the operating system may know, what LRU,LFU,FIFO,FILO and so on, I put this in the later Redis algorithm mechanism to say.
Local cache and distributed cache
First look at the example, or NBA players, now my memory is too small, each computer can only store the data of one NBA player, but now I have 3 player data need to be stored in the computer?
Local cach
Local cache is to store data in local memory, because there is no need to connect to other hosts through the network, the natural speed is also the fastest, of course, there are disadvantages. For example, Mybatis first-and second-level cache, Caffeine,Guava are typical examples of local cache. Going back to the previous example, three players are placed on three different hosts, and the architecture using local caching looks like this:
Advantages:
High speed, no need to transmit through the network
Disadvantages:
Limited cache capacity available per host
Multiple nodes cannot share data
Distributed cache
Distributed cache is to use the network to store the cache on a host, so the capacity limit of the cache is the memory size of the cache machine, and its IO bottleneck is the network speed. Redis is a typical distributed cache, and of course, we can also turn Redis into a downright local cache without network calls.
Of course, the above figure is not accurate. Since the cache is distributed, it cannot be deployed on only one cache machine. It is often deployed in a cluster manner.
This is the end of "what is Redis caching". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.