home page
Leaving a message.
Friendly chain
Drum kit
more
wallpaper
live broadcast
Time machine
about
Search
one
Gudou TV live broadcast agent source code, Gudou agent principle analysis
44718 Reading
two
Huawei Hongmeng system cannot install xapk APP (youtube advanced)
26631 Reading
three
[Reprint] Qinglong panel+Ninja zero installation tutorial
19035 Reading
four
Docker's typecho image - not recommended
12996 Reading
five
Typecho plug-in - download theme online to the server - addTheme publish
8773 Reading
technology
php
linux
mysql
redis
typecho
nginx
go
python
dnmp
tool
diary
Financial diary
Life diary
life
Kindle resources
Notice
virtual machine
Sign in
Search
Tag Search
msyql
Principal and subordinate
Huawei
Hongmeng
xapk
Flashback
APP flash back
kindle
mobi
docker
pip
alpine
Xiaoxiami of Menglang
Accumulated writing
one hundred and thirty-two
Articles
Accumulated receipt
five hundred and sixty
Comments
home page
column
technology
php
linux
mysql
redis
typecho
nginx
go
python
dnmp
tool
diary
Financial diary
Life diary
life
Kindle resources
Notice
virtual machine
page
Leaving a message.
Friendly chain
Drum kit
wallpaper
live broadcast
Time machine
about
Search to
two
Article and
Results for
2022-07-27
Record a Redis divine operation - also known as pit stepping diary
The preface has not updated the blog for a long time, and I have updated it again.
The problem encountered this time is to delete keys and query keys in Redis.
The project background is the old rule. Let's start with the project background.
The original mall project was opened for the second time, and the customer requested to add a nearby function. We already have the nearby merchant function, so we just need to open it to go up.
If the question is so simple, then I don't have any articles to write?
Of course not.
After the project is put into the test environment, the product is tested, and the feedback is that the banner and commodity list on the home page cannot be managed.
My first reaction is that this function is good. It must be that the new product doesn't understand anything.
But in order to prevent being slapped on the face, I made a special attempt, and the result was really problematic.
View the code. It is found that Redis has been deleted in the background, but the deletion is not complete.
Because N programmers have developed this block, the function of this block is extremely crowded, like shit, and various operations.
Now the demand is that each city and each region has a corresponding merchant to choose from. If there is no merchant, a designated city will be selected by default.
A programmer wrote a magic operation: if there is no data of a certain city in the background, take the data of the default city and put it in the city, then a magic thing happened here: when the background manages the city data, such as updating or deleting the city data, but there is no data of the city in the front end,
This causes the background to delete the relevant Redis, but not the existing Redis.
For example, the user requests the data of Beijing in the front end, but there is no Beijing in the back end, so the data of Shenzhen is given to Beijing by default, and is cached in the data whose key is Beijing in Redis. At this time, when updating Shenzhen or adding Beijing in the back end, Redis does not do the corresponding update operation.
Solution How to solve this problem?
For the sake of speed, I added a set directly.
Set a set, and put the nonexistent keys in the set, so that each time you can judge whether they are not in the set, and when you delete them in the background, you can judge whether the corresponding city keys exist in the set, and delete the corresponding values in the set if they exist.
Other logic shall be executed as usual.
For example, the existing city cache is directly deleted (unlink). Why don't you write in the background?
Because this key may not have access to the afterword efficiency and function analysis for a long time, when changing this logic, various considerations were taken, and this method was finally used. The reason is that the set is a little less repetitive than the list, that is, the data duplication problem is ignored.
Why not use an ordered set? Because you don't need to sort, you just need to know whether it exists.
Business analysis: the original version: the corresponding city Redis cache cannot be deleted. The first version is modified: the collection is added. When deleting in the background, use hscan+unlink to delete the collection and the cached city key, and then the original logic remains unchanged.
Fastest implementation.
At this time, the front end requests that the city data that does not exist in the background will be cached in memory, causing a waste of memory.
The second version has been modified: the front end first judges whether the city data exists. If not, it judges whether the city value exists in the collection. If it exists, it returns the default city cache.
The background only needs to delete the new values in the collection.
Thank you for your article reference
https://blog.csdn.net/u012998306/article/details/105417611
Redis sadd command and delete the set set or delete one or more records in the set separately
https://bbs.huaweicloud.com/blogs/317523
In order to grasp the Redis data structure, I drew 40 pictures (full version)
https://blog.csdn.net/fuzhongmin05/article/details/119531696
How Data Structure Makes Redis Fast
http://jinguoxing.github.io/redis/2018/09/04/redis-scan/
Use of scan
https://www.lixueduan.com/post/redis/redis-scan/
Redis Scan principle analysis and pit stepping
https://nyogjtrc.github.io/posts/2019/12/delete-keys-matching-a-pattern-in-redis/
Delete K conforming to Pattern in Redis
eyhttps://redis.io/commands/unlink/
unlink
http://mysql.taobao.org/monthly/2018/10/05/
Redis lazyfree · Gospel deleted by big key
https://blog.csdn.net/loophome/article/details/105204427
Redis Delete Large Collection Operation (Lists, Sets)
July 27, 2022
1800 Reading
0 Comments
0 likes
Have no foundation to learn Redis like this?
it will work
March 26, 2022
622 Reading
0 Comments
0 likes
2022-03-26
Recently, I was looking at Zhou Yang's Redis large factory team. There are not many instructions for using basic commands, but I said what the bottom layer of Redis is like, which is highly recommended.
The name of this video is Redis6, the ultimate performance of distributed storage. Station B doesn't know whether there is one. It's really good. It's recommended.
Don't blame your brothers for "keeping pictures instead of seeds". You have to find this kind of seeds by yourself. You can do it in any way. Anyway, the name is given to you. What else can stop you