当前位置:网站首页>Redis usage scenario
Redis usage scenario
2022-07-25 10:36:00 【colours starry sky】
1、 cache
Redis Today's most familiar use scenarios . It's very effective in improving server performance ; Some frequently accessed data , If the frequently accessed data is placed in a relational database , Every query costs a lot , And put it in redis in , because redis It's in memory and can be accessed very efficiently .
for example : Hot data cache ( For example, report 、 Star cheating ), Object caching 、 Full page caching 、 Can improve access to hotspot data .
2、 Data sharing distributed
String type , because Redis It's a distributed, stand-alone service , It can be shared among multiple applications
for example : Distributed Session
1 2 3 4 |
|
Default Session It's stored in a file on the server , If it's a cluster service , The same user may fall on different machines , This will cause users to log in frequently ; use Redis preservation Session after , No matter which machine the user falls on, they can get the corresponding Session Letter Rest .
3、 Ranking List
Using traditional relational databases (mysql oracle etc. ) To do this , Very troublesome , And the use of Redis Of SortSet( Ordered set ) Data structure can be done easily ;

4. Luck draw
With a random value
1 |
|
5、 The shopping cart
String or hash. all String What can be done hash You can do it.

- key: user id;field: goods id;value: The number .
- +1:hincr.-1:hdecr. Delete :hdel. Future generations :hgetall. Number of goods :hlen.
6、 Calculator / Speed governor
int type ,incr Method
Redis Self increasing operation of middle atomicity , We can count the likes of similar users 、 Number of user visits, etc , If this kind of operation is used MySQL, Frequent reading Writing can bring considerable pressure ; The typical use scenario of speed limiter is to restrict a user's access to a certain API The frequency of , Commonly used when there is a rush to buy , prevent Stop unnecessary pressure caused by users' crazy clicks ;
7、 Simple message queuing
except Redis Own release / A subscription model , We can also use it List To implement a queuing mechanism , such as : Notice of arrival 、 E-mail sending and so on demand , No need for high reliability , But it will bring very big DB pressure , It can be used completely List To achieve asynchronous decoupling ;
List Two blocked pop-up operations are provided :blpop/brpop, Timeout can be set
- blpop:blpop key1 timeout Remove and get the first element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found .
- brpop:brpop key1 timeout Remove and get the last element of the list , If there are no elements in the list, it will block the list until the wait timeout or pop-up elements are found .
Operation above . In fact, that is java Blocking queue . The more you learn . The lower the cost of learning
- queue : First in, first out :rpush blpop, Left head right tail , Right into the queue , Queue left
- Stack : First in, then out :rpush brpop
8、 Distributed lock
In the distributed environment , You cannot use locks in a stand-alone environment to synchronize processes on multiple nodes . have access to Redis Self contained SETNX command Implement distributed locks , besides , You can also use the official RedLock Distributed lock implementation .
1 2 3 4 5 6 7 8 9 10 11 |
|
String type setnx Method , Only when it doesn't exist can it be added successfully , return true
边栏推荐
- 6. Regular expression of shell
- Angr (VII) -- angr_ ctf
- How to connect tdengine through open source database management tool dbeaver
- About the jar package of slf4j log4j log4j2 used together
- Erlang (offline deployment)
- For cycle: daffodil case
- Number theory -- negative Radix conversion
- Angr (VIII) -- angr_ ctf
- Vscode latex workshop set xelatex compilation
- Mysql5.7 master-slave database deployment (offline deployment)
猜你喜欢
随机推荐
disabled和readonly 以及焦点问题
Vscode latex workshop set xelatex compilation
Pytorch tensor list is converted to tensor list of tensor to tensor using torch.stack()
Open virtual private line network load balancing
3.跟你思想一样DNS域名解析服务!!!
9.shell文本处理三剑客之awk
3. Believe you can understand! Circular statements and functions of shell scripts, arrays, bubble sorting
2. Introduce the deployment of lamp platform +discuz Forum
部署主从数据库
js 双向链表 02
VLAN configuration and application (take Huawei ENSP as an example)
Erlang (offline deployment)
Number theory -- Research on divisor
2021 京东笔试总结
Multithreading - static proxy mode
Angr(三)——angr_ctf
Angr(五)——angr_ctf
Selenium waits for the occurrence of elements and the conditions under which the waiting operation can be performed
8.shell文件处理三剑客之sed
Frp反向代理部署









