当前位置:网站首页>A complete tutorial for getting started with redis: redis usage scenarios

A complete tutorial for getting started with redis: redis usage scenarios

2022-07-04 22:59:00 Gu Ge academic

1.3.1 Redis What can be done
1. cache
Caching mechanism is used in almost all large websites , Reasonable use of cache can not only add
Fast data access speed , And it can effectively reduce the pressure of back-end data sources .Redis Provides
Key value expiration time setting , It also provides the elimination strategy after flexibly controlling the maximum memory and memory overflow
A little . You can say that , A reasonable cache design can guarantee the stability of a website . The first
11 This chapter will describe the design and use of cache in detail .
2. Ranking system
Ranking system exists in almost all websites , For example, ranking by popularity , according to
Ranking list of release time , Rankings calculated from various complex dimensions ,Redis Provides a list
And ordered set data structures , Using these data structures reasonably can easily build various rankings
List system .
3. Counter application
Counters play an important role in websites , For example, the video website has the number of plays 、 E-commerce websites have
Browse the number , In order to ensure real-time data , Every time you play and browse, you have to add 1 The operation of , Such as
As a result, the large amount of concurrency is a challenge to the performance of traditional relational data .Redis Natural support count
Function and counting performance is also very good , It is an important choice of counter system .
4. Social networks
Fabulous / Step on 、 fans 、 Common friends / like 、 push 、 Pull down and refresh are necessary functions of social networking sites , Because social networking sites are usually heavily visited , Moreover, the traditional relational data is not suitable for saving
This type of data ,Redis The data structure provided can realize these functions relatively easily
can .
5. Message queuing system
Message queuing system can be said to be a necessary basic component of a large website , Because it has a business
decoupling 、 Non real time service peak shaving and other features .Redis It provides publish and subscribe function and blocking queue function
can , Although it's not strong enough compared to a professional message queue , But for general message queuing functions
Can basically satisfy .

1.3.2 Redis What can't be done
In fact, like any technology , Each technology has its own application scenarios and boundaries , also
That is to say Redis It's not a panacea , There are a lot of problems that it can solve , But there are also many disagreements
The problem it solves . We can analyze it from the perspective of data scale and hot and cold data .
From the perspective of data scale , Data can be divided into large-scale data and small-scale data , We
know Redis Is stored in memory , Although memory is cheap enough now , But like
The amount of data is very large , For example, there are hundreds of millions of user behavior data every day , Use Redis To store the
word , It's basically a bottomless hole , The economic cost is quite high .
From a data perspective , The data is divided into hot data and cold data , Thermal data usually refers to the need
Data to be operated frequently , On the contrary, it is cold data , For example, for video sites , Basic video information
Basically, there are data that need to be operated frequently in all business lines , And the user's viewing record is not necessarily through
Data that often needs to be accessed , Let's not discuss the difference of data scale between the two , Simply stand on the data cold
From the perspective of heat , Video information belongs to hot data , User viewing records are cold data . If the
Put some cold data on Redis in , It's basically a waste of memory , But for some heat numbers
It can be put in Redis Speed up reading and writing in , It can also reduce the load of back-end storage , It can be said to be half done
Work twice .
therefore ,Redis It's not a panacea , I believe that with our understanding of Redis Step by step learning , Can clear
Chu Redis Real use scenarios .

1.4  The use of good Redis The advice of
1. Don't use it as a black box , Development is as important as operation and maintenance
Many uses Redis Most developers think that as long as they can use API Develop the corresponding functions , What's more
Even think Redis Namely get、set、del, You don't need to know Redis Principle . But in our reality
International transportation and peacekeeping use Redis In the process of discovery , A lot of online failures and problems are due to completely
Redis As a black box , If you don't understand Redis Single thread model , Some developers will have
Tens of millions of keys Redis On the implementation keys* operation , If you don't understand the principles of persistence , Will be in
A large number of write operations Redis The configuration is saved automatically RDB. And in many companies, there are only specialized
Job relational database DBA, did not NoSQL The relevant operation and maintenance personnel , That is to say, developers
It is likely to operate and maintain by itself Redis, about Redis It's both a good thing and a bad thing for developers . standing
On the bright side , Developers can use operation and maintenance Redis Really understand Redis Some of the principles , No
Simply stay on development . On the bad side ,Redis It's not just about supporting development ,
We have to take the responsibility of operation and maintenance , Moreover, due to lack of operation and maintenance experience, it may cause online failure . But from
From practical experience , Operation and maintenance is of sufficient scale Redis Will make good use of Redis More helpful .
2. Read the source code
We mentioned earlier ,Redis It's an open source project , Because of the author's understanding of Redis The ultimate pursuit of code
seek ,Redis The amount of code is relative to many NoSQL Database is very small , That means
As an ordinary development and operation and maintenance personnel, you can “ Read and ”Redis Of . By reading excellent sources
code , Not only can we deepen our understanding of Redis The understanding of the , And it can also improve its coding level ,
You can even be right Redis Make it customized , That is to say, it can be modified Redis Source code to meet their own needs
seek , For example, Sina Weibo is Redis The early version of has made a lot of customization to meet their own needs , Pea pod is also open source based on Proxy Of Redis Distributed implementation Codis.

原网站

版权声明
本文为[Gu Ge academic]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/185/202207042229264300.html