当前位置:网站首页>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
边栏推荐
猜你喜欢

SOC project AHB_ SD_ Host controller design

1.4 - fixed and floating point numbers

Force buckle ------ replace blank space

gazebo/set_ model_ State topic driving UAV model through posture

KEIL - 下载调试出现“TRACE HW not present”

Bat usage details 2

【模糊神经网络】基于模糊神经网络的移动机器人路径规划

ETL为什么经常变成ELT甚至LET?

1.8 - multi level storage

相关数据库问题提问。
随机推荐
ROS system problem: rosdep init
成品升级程序
判断h5在两端是在微信环境还是企业微信环境
【模糊神经网络】基于模糊神经网络的移动机器人路径规划
A small template (an abstract class, a complete process is written in a method, the uncertain part is written in the abstract method, and then the subclass inherits the abstract class, and the subclas
Definition and use of ROS topic messages
Fastapi learning Day2
List in set (2)
Joseph problem C language
Several C language implementations
Performance comparison of random network, scale-free network, small world network and NS small world matlab simulation
Fastapi learning Day1
Is Huatai stock trading safe? I want to open an account online.
关注这场直播,了解能源行业双碳目标实现路径
Relevant database questions.
Idea add database
Cocos studio3.1 installation package win
C language: exercise 3
Set in set (III)
Pycharm shortcut key