CN113254465B - Cache final consistency updating method - Google Patents

Cache final consistency updating method Download PDF

Info

Publication number
CN113254465B
CN113254465B CN202110572535.6A CN202110572535A CN113254465B CN 113254465 B CN113254465 B CN 113254465B CN 202110572535 A CN202110572535 A CN 202110572535A CN 113254465 B CN113254465 B CN 113254465B
Authority
CN
China
Prior art keywords
program
redis
cache
data
updating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110572535.6A
Other languages
Chinese (zh)
Other versions
CN113254465A (en
Inventor
陈锦鹏
鲜青林
彭一亮
邓文科
宋舰
曾辉
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Sichuan Hongmagic Cube Network Technology Co ltd
Original Assignee
Sichuan Hongmagic Cube Network Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Sichuan Hongmagic Cube Network Technology Co ltd filed Critical Sichuan Hongmagic Cube Network Technology Co ltd
Priority to CN202110572535.6A priority Critical patent/CN113254465B/en
Publication of CN113254465A publication Critical patent/CN113254465A/en
Application granted granted Critical
Publication of CN113254465B publication Critical patent/CN113254465B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Abstract

The invention discloses a cache final consistency updating method, which guarantees cache final consistency based on a Redis queue, and specifically comprises the following steps: when a business system needs to modify data in a Redi s program, firstly, acquiring a current incr value of a corresponding cache mark from the Redi s program; the service system assembles data needing to be updated, wherein the assembly content comprises cache information, an incr value and a cache content type, and then performs left enqueue operation on a specified queue of the Redis program, namely the push operation of the Redis program; when the timing task is triggered, the timing updating program is responsible for performing right dequeuing operation on the specified queue of the Redis program, namely the brpop operation of the Redis program; judging whether a result obtained by the right dequeuing operation of the Redis program is empty or not, and updating the cache; the invention ensures the final consistency of the data in the database and the data in the Redis program.

Description

Cache final consistency updating method
Technical Field
The invention relates to the technical field of data updating, in particular to a cache final consistency updating method.
Background
With the increasing of the amount of the services, the demand for the servers also increases, so that the service system with the same function does not deploy only one server, but deploys a plurality of service systems on different servers. Since some common data among the business systems are placed in the Redis program, and the business systems also query and modify the data in the Redis program, inconsistency between the data in the Redis program and the data in the database may be caused.
Disclosure of Invention
In order to solve the problems in the prior art, the invention aims to provide a cache final consistency updating method, and the final consistency of data in a database and data in a Redis program is ensured by utilizing a queue of the Redis program, an incr command of the Redis program and data content and data identification in the queue.
In order to achieve the purpose, the invention adopts the technical scheme that: a cache final consistency updating method guarantees cache final consistency based on a Redis queue, and specifically comprises the following steps:
step 1, when a business system needs to modify data in a Redis program, firstly, acquiring a current incr value of a corresponding cache mark from the Redis program;
step 2, the service system assembles data to be updated, wherein the assembled content comprises cache information, an incr value and a cache content type, and then performs left enqueuing operation on a specified queue of the Redis program, namely the lpush operation of the Redis program;
step 3, when the timing task is triggered, the timing updating program is responsible for carrying out right dequeuing operation on the specified queue of the Redis program, namely the brpop operation of the Redis program;
step 4, judging whether a result obtained by the right dequeue operation of the Redis program is null: if the result obtained by the right dequeue operation of the Redis program is not null, updating the cache; and if the result obtained by the right dequeue operation of the Redis program is empty, finishing the execution of the timing updating program and waiting for the next awakening.
As a further improvement of the present invention, in step 4, if a result obtained by the right dequeue operation of the Redis program is not null, the updating the cache specifically includes the following steps:
4.1, the program is updated regularly to analyze the result obtained by the dequeue operation, obtain the incr value of the corresponding cache mark, judge whether the incr value obtained is consistent with the incr value of the result obtained by the dequeue operation, if so, the data belongs to the latest database data, and the data belongs to the content which can be updated to the Redis program cache; if not, then the data is not up-to-date, and the update should be skipped;
step 4.2, when the data belongs to the cache data which should be updated to the Redis program, updating the incr value of the corresponding cache mark in the Redis program, namely performing incr operation on the cache mark;
and 4.3, updating the analyzed data into a Redis program to replace the previous data.
The invention has the beneficial effects that:
the invention ensures that the data in the Redis program is consistent with the data in the database through the function based on the Redis queue, the incr command of the Redis program, the data content and the data identification in the queue and a single thread timing updating program which is specially used for updating the cache of the Redis program, thereby solving the problem of final consistency.
Drawings
FIG. 1 is a block flow diagram of embodiment 1 of the present invention;
fig. 2 is a flow chart of embodiment 2 of the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings.
Example 1
As shown in fig. 1, a cache final consistency updating method guarantees final consistency of data in a database and data in a Redis program by using a queue of the Redis program, an incr command of the Redis program, and data content and data identification in the queue; the method specifically comprises the following steps:
1. when a business system needs to modify data in a Redis program, firstly, a current incr value of a corresponding cache mark needs to be acquired from the Redis program;
2. the business system assembles data needing to be updated, assembles content cache information, and also comprises an incr value and a cache content type, and then performs left enqueuing operation on a specified queue of the Redis program, namely the lpush operation of the Redis program;
3. when the timing task is triggered, the timing updating program is responsible for performing right dequeuing operation on the specified queue of the Redis, namely the brpop operation of the Redis program;
4. if the result obtained by the right dequeue operation of the Redis program is not null, the following operations are performed:
4.1, analyzing the result obtained by the dequeue operation by the timing updating program, obtaining the incr value of the corresponding cache mark, judging whether the obtained incr value is consistent with the incr value of the analyzed result, and if so, indicating that the data belongs to the latest database data and belongs to the content which can be updated into the cache of the Redis program; if not, then the data is not up-to-date, and the update should be skipped;
4.2, when the data belongs to the cache data which should be updated into the Redis program, in this step, the incr value of the corresponding cache mark in the Redis program is updated first, i.e. incr operation is performed on the cache mark.
4.3, updating the analyzed data into the Redis program to replace the previous data
5. And if the result obtained by the right dequeue operation of the Redis program is empty, finishing the execution of the timing updating program and waiting for the next awakening.
Example 2
The key names in this embodiment include the following:
a. incr _ index _ single _ code: the type of single _ code buffer updated incr value.
b. incr _ index _ flag: and the business system enqueues the left and updates the cache key of the Redis program listed on the right of the program regularly.
c. singleCodeCacheDTO: the data format used in the incr _ index _ flag queue mainly contains the value of incr, which is hereinafter denoted as incrNum, and the associated traffic data.
d. incr _ type _ single _ code: for identifying the type of cache update.
The steps of this embodiment are further described below with reference to fig. 2:
1. and a service system step:
1.1, a service system finds cache information of a Redis program of a singCode to be updated;
1.2, the service system acquires the value incrNum with key being incr _ index _ single _ code through get operation of Redis, then puts incrNum into single CodeCacheDTO, then puts incr _ type _ single _ code into single CodeCacheDTO, and enqueues the single CodeCacheDTO to the left of the incr _ index _ flag queue through the lpush command of the Redis program.
2. The timing updating program step:
2.1, the timing updating program meets the timing task configuration and starts to be started;
2.2, carrying out right dequeuing operation on the incr _ index _ flag queue in the Redis program by the timing updating program, and obtaining single CodeCacheDTO by using a command brpop command;
2.3, if singleCodeCacheDTO is not empty:
2.3.1, obtaining that the cache type is incr _ type _ single _ code in the single CodeCacheDTO object, determining that the single code information is updated, and then obtaining the value in the Redis program by taking the incr _ index _ single _ code as key;
2.3.2, comparing the value obtained from the program with incrNum in singleCodeCacheDTO;
2.3.2.1, if incrNum is consistent with the value in the cache:
2.3.2.1.1, updating the service information in the singleCodeCacheDTO into a Redis cache;
2.3.2.1.2, updating the value of incr _ incex _ single _ code in the Redis program;
2.3.2.2, if incrNum is not consistent with the value in the buffer memory, if the value is not consistent, it indicates that the data is not the newest data, and skips the update; the program resumes executing step 2.2 of this example;
and 2.4, if the singleCodeCacheDTO is empty, the updating is finished, and the timing task waits for the next starting.
The above-mentioned embodiments only express the specific embodiments of the present invention, and the description thereof is more specific and detailed, but not construed as limiting the scope of the present invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the inventive concept, which falls within the scope of the present invention.

Claims (1)

1. A cache final consistency updating method is characterized in that cache final consistency is guaranteed based on a Redis queue, and the method specifically comprises the following steps:
step 1, when a business system needs to modify data in a Redis program, firstly, acquiring a current incr value of a corresponding cache mark from the Redis program;
step 2, the service system assembles data needing to be updated, wherein the assembled content comprises cache information, an incr value and a cache content type, and then performs left enqueue operation on a specified queue of a Redis program, namely the push operation of the Redis program;
step 3, when the timing task is triggered, the timing updating program is responsible for carrying out right dequeuing operation on the specified queue of the Redis program, namely the brpop operation of the Redis program;
step 4, judging whether a result obtained by the right dequeue operation of the Redis program is null: if the result obtained by the right dequeue operation of the Redis program is not null, updating the cache; if the result obtained by the right dequeue operation of the Redis program is empty, finishing the execution of the timing updating program and waiting for the next awakening;
in the step 4, if the result obtained by the right dequeue operation of the Redis program is not empty, updating the cache specifically includes the following steps:
4.1, the program is updated regularly to analyze the result obtained by the dequeue operation, obtain the incr value of the corresponding cache mark, judge whether the incr value obtained is consistent with the incr value of the result obtained by the dequeue operation, if so, the data belongs to the latest database data, and the data belongs to the content which can be updated to the Redis program cache; if not, then the data is not up-to-date, and the update should be skipped;
step 4.2, when the data belongs to cache data which should be updated to the Redis program, updating an incr value of a corresponding cache mark in the Redis program, namely performing incr operation on the cache mark;
and 4.3, updating the analyzed data into a Redis program, and replacing the previous data.
CN202110572535.6A 2021-05-25 2021-05-25 Cache final consistency updating method Active CN113254465B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110572535.6A CN113254465B (en) 2021-05-25 2021-05-25 Cache final consistency updating method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110572535.6A CN113254465B (en) 2021-05-25 2021-05-25 Cache final consistency updating method

Publications (2)

Publication Number Publication Date
CN113254465A CN113254465A (en) 2021-08-13
CN113254465B true CN113254465B (en) 2022-11-01

Family

ID=77184314

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110572535.6A Active CN113254465B (en) 2021-05-25 2021-05-25 Cache final consistency updating method

Country Status (1)

Country Link
CN (1) CN113254465B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105447740A (en) * 2015-11-17 2016-03-30 北京齐尔布莱特科技有限公司 Anti-scalping method based on Golang
CN106874424A (en) * 2017-01-25 2017-06-20 杭州淘淘搜科技有限公司 A kind of collecting webpage data processing method and system based on MongoDB and Redis
CN107623613A (en) * 2017-09-13 2018-01-23 微赫智能科技(上海)有限公司 Intelligent household system
CN107894919A (en) * 2017-11-30 2018-04-10 中国平安财产保险股份有限公司 Timed task triggering method, device, equipment and readable storage medium storing program for executing
CN109918191A (en) * 2017-12-13 2019-06-21 北京京东尚科信息技术有限公司 A kind of method and apparatus of the anti-frequency of service request
CN110413650A (en) * 2019-07-31 2019-11-05 广州虎牙科技有限公司 A kind of processing method of business datum, device, equipment and storage medium
CN110750506A (en) * 2019-09-17 2020-02-04 苏宁云计算有限公司 Data object identification generation method and device, computer equipment and storage medium
CN111708685A (en) * 2020-05-18 2020-09-25 福建天晴在线互动科技有限公司 Log acquisition monitoring method and system for distributed server
CN112256954A (en) * 2020-09-08 2021-01-22 国网宁夏电力有限公司经济技术研究院 Message pushing processing method and related system

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108304408B (en) * 2017-01-12 2021-04-02 中国移动通信集团公司 Cache data refreshing method and device
CN110119487B (en) * 2019-04-15 2021-07-16 华南理工大学 Cache updating method suitable for divergent data
CN110471868A (en) * 2019-08-21 2019-11-19 携程旅游信息技术(上海)有限公司 Improve method, system, equipment and the medium of SOA interface response speed
CN111221861B (en) * 2019-12-31 2023-06-02 武汉中海庭数据技术有限公司 Method and device for synchronizing local cache and database data
CN111563102A (en) * 2020-04-10 2020-08-21 中国联合网络通信集团有限公司 Cache updating method, server, system and storage medium
CN111858556A (en) * 2020-07-22 2020-10-30 浪潮云信息技术股份公司 Distributed cache management method based on version control and manager
CN112699325B (en) * 2021-01-14 2022-07-26 福建天晴在线互动科技有限公司 Method and system for guaranteeing data consistency through cache secondary elimination

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105447740A (en) * 2015-11-17 2016-03-30 北京齐尔布莱特科技有限公司 Anti-scalping method based on Golang
CN106874424A (en) * 2017-01-25 2017-06-20 杭州淘淘搜科技有限公司 A kind of collecting webpage data processing method and system based on MongoDB and Redis
CN107623613A (en) * 2017-09-13 2018-01-23 微赫智能科技(上海)有限公司 Intelligent household system
CN107894919A (en) * 2017-11-30 2018-04-10 中国平安财产保险股份有限公司 Timed task triggering method, device, equipment and readable storage medium storing program for executing
CN109918191A (en) * 2017-12-13 2019-06-21 北京京东尚科信息技术有限公司 A kind of method and apparatus of the anti-frequency of service request
CN110413650A (en) * 2019-07-31 2019-11-05 广州虎牙科技有限公司 A kind of processing method of business datum, device, equipment and storage medium
CN110750506A (en) * 2019-09-17 2020-02-04 苏宁云计算有限公司 Data object identification generation method and device, computer equipment and storage medium
CN111708685A (en) * 2020-05-18 2020-09-25 福建天晴在线互动科技有限公司 Log acquisition monitoring method and system for distributed server
CN112256954A (en) * 2020-09-08 2021-01-22 国网宁夏电力有限公司经济技术研究院 Message pushing processing method and related system

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
Redis 原子计数器 incr,防止并发请求;张小鸣;《https://blog.csdn.net/Roy_70/article/details/78260826》;20171017;1-2 *
redis简单:消息队列-高并发-超抢/卖;传说中的生生;《https://www.cnblogs.com/emmmmmm/p/10061126.html》;20181203;1-3 *
高并发下Redis如何保持数据一致性(避免读后写);grey;《https://blog.csdn.net/u011832039/article/details/78924418》;20171228;1-4 *

Also Published As

Publication number Publication date
CN113254465A (en) 2021-08-13

Similar Documents

Publication Publication Date Title
CN110321387B (en) Data synchronization method, equipment and terminal equipment
CN107908631B (en) Data processing method, data processing device, storage medium and computer equipment
CN108959292B (en) Data uploading method, system and computer readable storage medium
CN108023908B (en) Data updating method, device and system
CN111917863B (en) Message pushing method and device, television equipment and computer storage medium
CN104391725A (en) Page display method and page display device
CN111367925A (en) Data dynamic real-time updating method, device and storage medium
CN112214617B (en) Digital file management method and system based on block chain technology
CN111400298A (en) Data processing method and device and computer readable storage medium
CN111400407A (en) Data synchronization method and device, storage medium and electronic device
CN112347143A (en) Multi-data stream processing method, device, terminal and storage medium
CN113254465B (en) Cache final consistency updating method
CN110389817B (en) Scheduling method, device and computer readable medium of multi-cloud system
CN110781064A (en) Method and device for dynamically embedding point to acquire client user behavior data
CN108280215B (en) Hybrid updating method of E-commerce index file based on Solr
CN110019012B (en) Data preprocessing method, data preprocessing device and computer-readable storage medium
CN104486393A (en) Resource configuration and recycling method and resource configuration and recycling system
CN110221988B (en) Cache optimization method and system for third-party data
CN110019179A (en) Update method and device, the electronic equipment, storage medium of index database
CN109739836B (en) Method and system for multi-version database selection and update of timestamps
CN106055640A (en) Buffer memory management method and system
CN111831688A (en) Management method and management system of operation and maintenance data
CN113900991A (en) Data interaction method, device, equipment and storage medium
CN109586970B (en) Resource allocation method, device and system
CN109086279B (en) Report caching method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant