当前位置:网站首页>Redis cache
Redis cache
2022-06-30 06:46:00 【Sunny husband】
The front page is usually a page with a domain name ( Servers or clusters ), In particular, the pressure of visiting the home page is relatively large , Therefore, the front-end advertisements need to use caching to relieve the pressure of database access , Speed up access
Sometimes an error is reported when uploading pictures , Unable to resolve the address of the image server , The reason is that the configuration file is not compiled to target, Therefore, it cannot be resolved in the method Should first clean To compile
And that is s c o p e . e n t i t y . p i c Meeting newspaper wrong say p i c not set The righteous primary because Just yes cheng order No know Avenue e n t i t y yes No yes One individual Yes like I People can With First set The righteous scope.entity.pic Will report a mistake pic Undefined The reason is that the program doesn't know entity Is it an object We can define scope.entity.pic Meeting newspaper wrong say pic not set The righteous primary because Just yes cheng order No know Avenue entity yes No yes One individual Yes like I People can With First set The righteous scope.entity ={} ( It is best to bind stand-alone events to the new buttons in the page ng-click=‘entity={}’)
Use redis The situation of : Frequent visits , Large amount of visits , Less content change , The content is relatively unimportant
How to reduce the pressure of database access :1. Data caching 2. Page static
When caching, you should connect redis,redis There is a configuration file to load , The address of the server , Port number , Timeout time , Maximum number of connections, etc
in addition redis There is one spring The configuration file , It's equipped with a redis object , One redisConnection object One redisTemplate object
redisTemplate operation
Delete a key value pair delete(“ Key name ”)
add to String Type value boundValueOps(“ Key name ”).set(“ Content ”)
obtain String Type value boundValueOps(“ Key name ”).get()
add to set Type value boundSetOps(“ Key name ”).add( Value content )
obtain set Type value boundSetOps(“ Key name ”).members()
Delete one of the values boundSetOps(“ Key name ”).remove(“ value ”)
add to list Type value boundListOps(“ Key name ”).rightPush/leftPush( Value content )
obtain list All values of type boundListOps(“ Key name ”).range( Starting index , The number of data )
Delete one of the values boundListOps(“ Key name ”).remove( Number of deletions ,“ value ”) If the number written is less than 1 Delete at least one , If you write more than one, you can delete several within the deleted quantity
obtain list A value of type boundListOps(“ Key name ”).index( Indexes )
add to hash Type value boundHashOps(“ Key name ”).put(“key1”, value 1)
obtain hash Type value boundHashOps(“ Key name ”).get(“key1”)
Delete one of the values boundHashOps(“ Key name ”).delete(“key1”)
Get all key boundHashOps(“ Key name ”).keys()
Get all values boundHashOps(“ Key name ”).values()
redis Cache emptying problem
The data query should first query the cache , The cache no longer queries the database , But the cached data must be consistent with the database data , Therefore, the corresponding cache should be emptied when adding, deleting or modifying , However, the cache data of all advertisements cannot be cleared when clearing the cache , The type of advertisement that should be emptied should be changed , So there is a big key, Then there are many small key
When adding, deleting, or modifying, the cache is emptied differently
When adding, empty the cache of the added type
When deleting, you can delete this type , However, deleting involves deleting multiple , To avoid duplicate deletion of the same type of cache , You can put the type of deleted advertisement into a set aggregate , Delete after de duplication , Avoid repeated operations
The modification involves the modification of the advertisement type , In this case, you should clear the cache of the type before and after the change , To avoid duplicate deletion, you can judge whether the types are the same
JPA Java Persistence API java Persistence layer API ORM Object Relational Mapping Object relation mapping
边栏推荐
- RT thread Kernel Implementation (II): critical area, object container
- Problems and solutions of creating topic messages in ROS
- Unable to access the Internet at win10 /11 hotspot
- 1.9 - 存储器的分类
- Set in set (III)
- 史上最全一句话木马
- Collections tool class (V)
- Control method of UAV formation
- ini解析學習文檔
- Connect to remote server
猜你喜欢
随机推荐
RT thread migration to s5p4418 (I): scheduler
【模糊神经网络】基于模糊神经网络的移动机器人路径规划
【json-tutorial】第一章学习笔记
High performance distributed execution framework ray
Force buckle ------ replace blank space
1.6 - CPU组成
Ini parsing learning documents
Definition and use of ROS topic messages
成品升级程序
圖像處理7-圖像增强
The 40g high-efficiency cloud disk purchased by Alibaba cloud is only 20g attached
Go installation and configuration (1)
RT thread Kernel Implementation (II): critical area, object container
记录一次腾讯测试开发工程师自动化接口测试实践经验
[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network
Notes: environment variables
First experience of Galaxy Kirin
原来你是这样的数组,终于学会了
0基础转行软件测试,如何实现月薪9.5k+
Ffmplay is not generated during the compilation and installation of ffmpeg source code





![[my creation anniversary] one year anniversary essay](/img/98/f9305894747687465f86354fe08500.png)



