In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces what the function of redis is, which has certain reference value, and friends who need it can refer to it. I hope you all have a lot to gain after reading this article. Let's take a look at it together.
Redis provides a wealth of features that may be confusing to see for the first time. What are these features for? What problems have been solved? Under what circumstances will the corresponding function be used? Here is a step-by-step explanation.
Native memory-based caching
In order to solve the problem that it still takes 2 seconds to call API, after investigation, the main reason is that it takes nearly 2 seconds to use SQL to get hot news. Therefore, we came up with a simple and rude solution, that is, directly cache the results of SQL queries in the memory of the current API server (set the cache validity time to 1 minute). Requests within the next 1 minute read the cache directly instead of taking 2 seconds to execute SQL. If this api receives 100 requests per second, then one minute is 6000, that is, only the first 2 seconds of crowded requests will take 2 seconds, and all the subsequent 58 seconds can be responded to without waiting another 2 seconds.
Server Redis
At a time when the API server's cache was full, we found ourselves having to think of another solution. The most straightforward idea is that we throw these caches on a dedicated server and make it a big memory configuration. And then we went after redis... As for how to configure and deploy redis, it is not explained here. Redis officially has a detailed introduction. Then we used a separate server as the Redis server, and the memory pressure of the API server was solved.
Persistence (Persistence)
A single Redis server is always in a bad mood for a few days a month. If it is in a bad mood, it will strike, resulting in the loss of all caches (redis data is stored in memory). Although the Redis server can be brought back online, due to the loss of data in memory, the cache avalanche is caused, and the pressure on the API server and database is still coming up at once. Therefore, at this time, Redis's persistence function comes in handy, which can alleviate the impact of cache avalanche. Redis persistence means that redis will write data from memory to hard disk and load it when redis restarts, thus minimizing the impact of cache loss.
Sentinel and Replication
Redis server strikes without warning are a nuisance. So what should we do? Answer: backup one, you hang it up. So how do you know that a redis server is down, how do you switch, and how do you ensure that the backup machine is a complete backup of the original server? Sentinel and Replication are needed. Sentinel can manage multiple Redis servers, providing monitoring, alerting, and automatic failover;Replication is responsible for enabling a Redis server to have multiple backups. Redis also uses these two features to ensure high availability of Redis. In addition, the Sentinel feature is an exploitation of Redis's publish and subscribe capabilities.
Cluster
There is always an upper limit to the resources of a single server. CPU resources and IO resources can be separated from each other through master-slave replication, and part of the CPU and IO pressure can be transferred to the slave server. However, what to do with memory resources, master-slave mode is only the backup of the same data, and can not expand the memory horizontally; the memory of a single machine can only be increased, but there is always an upper limit. So we needed a solution that would allow us to scale horizontally. The ultimate goal is to make each server responsible for only a part of it, so that all these servers form a whole. For external consumers, this group of distributed servers is like a centralized server.
Thank you for reading this article carefully. I hope that Xiaobian can share what the function of redis is to help everyone. At the same time, I hope that everyone will support more, pay attention to the industry information channel, find out if you encounter problems, and find detailed solutions waiting for you to learn!
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.