CN115455058A - Cache data processing method and device, computer equipment and storage medium - Google Patents

Cache data processing method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN115455058A
CN115455058A CN202211153999.4A CN202211153999A CN115455058A CN 115455058 A CN115455058 A CN 115455058A CN 202211153999 A CN202211153999 A CN 202211153999A CN 115455058 A CN115455058 A CN 115455058A
Authority
CN
China
Prior art keywords
data
time
cache data
processing
cache
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.)
Pending
Application number
CN202211153999.4A
Other languages
Chinese (zh)
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.)
Ping An Technology Shenzhen Co Ltd
Original Assignee
Ping An Technology Shenzhen 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 Ping An Technology Shenzhen Co Ltd filed Critical Ping An Technology Shenzhen Co Ltd
Priority to CN202211153999.4A priority Critical patent/CN115455058A/en
Publication of CN115455058A publication Critical patent/CN115455058A/en
Pending legal-status Critical Current

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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • 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/2457Query processing with adaptation to user needs
    • G06F16/24578Query processing with adaptation to user needs using ranking
    • 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/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Fuzzy Systems (AREA)
  • Mathematical Physics (AREA)
  • Probability & Statistics with Applications (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the application belongs to the field of data processing, and relates to a processing method of cache data, which comprises the following steps: judging whether a data updating operation triggered by a first user and corresponding to a database is received; if so, deleting the current first cache data of the Redis server; updating the original data in the database based on the data updating operation to obtain target data; acquiring time consumed by a reading request corresponding to a preset project, and determining sleep time based on the time consumed; and after the dormancy time, deleting the current second cache data corresponding to the target data of the Redis server. The application also provides a processing device, computer equipment and a storage medium for the cache data. In addition, the present application also relates to a blockchain technique in which second cache data can be stored in a blockchain. The data consistency between the cache data of the database and the cache data of the Redis server is effectively guaranteed based on the use of the dormancy time.

Description

Cache data processing method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a method and an apparatus for processing cache data, a computer device, and a storage medium.
Background
High concurrency is a common consideration in conventional projects of trading systems. In a high concurrency scenario, in order to relieve the pressure of a transaction system, a cache is often used in a conventional transaction system, and a Redis server is used as a technology. At present, when a transaction system receives a data request, firstly, whether the requested data is in Redis is checked, if the requested data is in Redis, the cached data is directly returned to a corresponding requester, and no operation is performed on a database; and if the requested data is not in Redis, searching the requested data in the database, returning the data searched from the database to the corresponding requester, and caching one copy of the data in Redis. However, in the case of high concurrency, when data in the database is updated, consistency between the database and the cached data of Redis cannot be guaranteed. For example, assuming that the transaction system currently receives two data requests, one for query operation A and one for update operation B, the situation may arise that 1. The data queried by request A is old data, and at this time the update operation of request B has not been updated. 2. The request B deletes the cache, the request A queries the cache as empty and queries the database, but the request B is not updated, so that the request A queries the old data, the data is disordered and can not be unified, and delay exists between the new data and the old data.
Disclosure of Invention
An object of the embodiments of the present application is to provide a method and an apparatus for processing cache data, a computer device, and a storage medium, so as to solve a technical problem that consistency between cache data of a database and a Redis cannot be guaranteed when data in the database is updated in the prior art.
In order to solve the foregoing technical problem, an embodiment of the present application provides a method for processing cache data, which adopts the following technical solutions:
judging whether a data updating operation triggered by a first user and corresponding to a database is received;
if so, deleting the current first cache data of the Redis server;
updating the original data in the database based on the data updating operation to obtain target data;
acquiring time consumed by a reading request corresponding to a preset project, and determining sleep time based on the time consumed;
and after the sleep time, deleting the current second cache data corresponding to the target data of the Redis server.
Further, the step of acquiring the time consumed by the read request corresponding to the preset item and determining the sleep time based on the time consumed by the read request specifically includes:
respectively acquiring first consumed time of all read requests in a preset time period corresponding to the preset item;
calculating the average value of all the first consumed time to obtain second consumed time;
acquiring a preset time consumption value;
calculating a sum between the second elapsed time and the elapsed time value;
and taking the sum as the sleep time.
Further, after the step of deleting the second cache data corresponding to the target data currently by the Redis server after the sleep time elapses, the method further includes:
judging whether the second cache data is failed to be deleted or not;
if the deletion fails, acquiring a first key value corresponding to the second cache data;
sending the first key value to a preset message queue so as to record a data deletion task corresponding to the second cache data in the message queue;
acquiring the first key value from the message queue;
and performing deletion retry processing on the second cache data obtained based on the first key value query.
Further, the step of obtaining the first key value corresponding to the second cache data specifically includes:
starting a preset subscription program;
acquiring a log file of the database based on the subscription program;
acquiring an operation log from the log file;
and acquiring the first key value corresponding to the second cache data from the operation log.
Further, the step of sending the first key value to a preset message queue specifically includes:
calling a preset processing program; the processing program is created and generated based on a preset non-business code;
receiving, by the handler, the first key value transmitted by the subscribing program;
sending the first key value to the message queue based on the handler.
Further, after the step of performing a retry of deletion on the second cached data obtained based on the keyword query, the method further includes:
obtaining a processing result obtained after the second cache data is subjected to deletion retry processing;
judging whether the processing result is deletion failure or not;
if so, generating alarm information corresponding to the second cache data;
acquiring communication information of a target user;
and sending the alarm information to the user terminal of the target user based on the communication information.
Further, the method for processing the cache data further includes:
judging whether a caching request for caching the specified data to the Redis server, which is triggered by a second user, is received;
if yes, setting a second key value corresponding to the specified data based on a preset lua script, and setting an expiration time corresponding to the second key value;
acquiring the specified data from the cache request;
caching the specified data into the Redis server based on the second key value and the expiration time.
In order to solve the foregoing technical problem, an embodiment of the present application further provides a processing apparatus for caching data, where the following technical solutions are adopted:
the first judgment module is used for judging whether data updating operation triggered by a first user and corresponding to the database is received;
the first deleting module is used for deleting the current first cache data of the Redis server if the first cache data of the Redis server is the current first cache data of the Redis server;
the updating module is used for updating the original data in the database based on the data updating operation to obtain target data;
the determining module is used for acquiring the time consumed by the reading request corresponding to the preset item and determining the sleeping time based on the time consumed;
and the second deleting module is used for deleting the second cache data corresponding to the target data currently by the Redis server after the dormancy time.
In order to solve the above technical problem, an embodiment of the present application further provides a computer device, which adopts the following technical solutions:
judging whether a data updating operation triggered by a first user and corresponding to a database is received;
if so, deleting the current first cache data of the Redis server;
updating the original data in the database based on the data updating operation to obtain target data;
acquiring time consumed by a reading request corresponding to a preset project, and determining sleep time based on the time consumed;
and after the dormancy time, deleting the current second cache data corresponding to the target data of the Redis server.
In order to solve the above technical problem, an embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solutions:
judging whether a data updating operation triggered by a first user and corresponding to a database is received;
if so, deleting the current first cache data of the Redis server;
updating the original data in the database based on the data updating operation to obtain target data;
acquiring time consumed by a reading request corresponding to a preset project, and determining sleep time based on the time consumed;
and after the sleep time, deleting the current second cache data corresponding to the target data of the Redis server.
Compared with the prior art, the embodiment of the application mainly has the following beneficial effects:
according to the embodiment of the application, when data updating operation triggered by a first user and corresponding to a database is received, current first cache data of a Redis server is deleted, then original data in the database is updated based on the data updating operation to obtain target data, time consumed by a reading request corresponding to a preset item is obtained subsequently, dormancy time is determined based on the time consumed, and finally second cache data corresponding to the target data of the Redis server are deleted after the dormancy time passes. According to the embodiment of the application, after the initial data stored in the database is updated, the dormancy time is determined based on the time consumed by the read request corresponding to the preset item, and then the current cache data of the Redis server is deleted according to the dormancy time, so that the cache data cached in the Redis server before the initial data is updated is deleted in a delayed manner, a data requester cannot acquire the initial data before the update, and the data consistency between the cache data of the database and the cache data of the Redis server is effectively ensured.
Drawings
In order to more clearly illustrate the solution of the present application, the drawings needed for describing the embodiments of the present application will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present application, and that other drawings can be obtained by those skilled in the art without inventive effort.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flow diagram of one embodiment of a method of processing cached data according to the present application;
FIG. 3 is a block diagram illustrating an embodiment of a processing device for caching data according to the present application;
FIG. 4 is a schematic block diagram of one embodiment of a computer device according to the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. It is explicitly and implicitly understood by one skilled in the art that the embodiments described herein can be combined with other embodiments.
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have various communication client applications installed thereon, such as a web browser application, a shopping application, a search application, an instant messaging tool, a mailbox client, social platform software, and the like.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture experts Group Audio Layer III, mpeg compression standard Audio Layer 3), MP4 players (Moving Picture experts Group Audio Layer IV, mpeg compression standard Audio Layer 4), laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the processing method for caching data provided in the embodiment of the present application is generally executed by a server/terminal device, and accordingly, the processing device for caching data is generally disposed in the server/terminal device.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for an implementation.
With continuing reference to FIG. 2, a flow diagram of one embodiment of a method of processing cached data in accordance with the present application is shown. The processing method of the cache data comprises the following steps:
step S201, determining whether a data update operation triggered by the first user and corresponding to the database is received.
In this embodiment, the electronic device (for example, the server/terminal device shown in fig. 1) on which the processing method for caching data operates may obtain the data updating operation in a wired connection manner or a wireless connection manner. It should be noted that the wireless connection means may include, but is not limited to, a 3G/4G/5G connection, a WiFi connection, a bluetooth connection, a WiMAX connection, a Zigbee connection, an UWB (ultra wideband) connection, and other wireless connection means now known or developed in the future. The data updating operation is an operation triggered by the first user to update original data in the database, and the data updating operation may include operations of adding, deleting, replacing, and the like to the data. The database may be mysql data.
Step S202, if yes, deleting the current first cache data of the Redis server.
In this embodiment, the Redis server is an open-source log-type and Key-Value database written in ANSIC language, supporting network, being based on memory and being persistent, and provides API in multiple languages. Some commonly used data are cached in the Redis server by introducing the Redis server, so that the data loading efficiency is well improved, and the reading and writing times of a database are reduced. The implementation logic of the query request to the Redis server is as follows: querying a Redis server firstly, querying a database if the data does not exist in the Redis server, and writing the data queried in the database into the Redis server so that the database is not required to be directly queried in the subsequent data query.
Step S203, updating the original data in the database based on the data updating operation to obtain target data.
In this embodiment, when a data update operation triggered by a first user and corresponding to a database is received, original data corresponding to the data update operation in the database is updated to obtain corresponding target data.
Step S204, acquiring the time consumed by the read request corresponding to the preset item, and determining the sleep time based on the time consumed.
In this embodiment, the preset items refer to associated items with which data interaction exists between the database and the Redis server. In the above, the specific implementation process of obtaining the time consumed by the read request corresponding to the preset item and determining the sleep time based on the time consumed is described in further detail in the following specific embodiments, and will not be described in detail herein.
Step S205, after the sleep time elapses, deleting the second cache data corresponding to the target data currently in the Redis server. After the initial data stored in the database is updated, the cache data cached in the Redis server before the initial data is updated can be successfully deleted, so that a data requester cannot acquire the initial data before the update, and the data consistency between the database and the cache data of the Redis server is effectively ensured.
In this embodiment, when the time corresponding to the hibernation time point is reached, the current second cache data corresponding to the target data of the Redis server is deleted immediately.
According to the data updating method and device, when data updating operation triggered by a first user and corresponding to a database is received, the current first cache data of the Redis server is deleted, then original data in the database is updated based on the data updating operation to obtain target data, time consumed by a reading request corresponding to a preset item is obtained subsequently, dormancy time is determined based on the time consumed, and finally after the dormancy time, the current second cache data corresponding to the target data of the Redis server is deleted. According to the method and the device, after the initial data stored in the database is updated, the dormancy time is determined based on the time consumed by the read request corresponding to the preset item, and then the current cache data of the Redis server is deleted according to the dormancy time, so that the cache data cached in the Redis server before the initial data is updated is deleted in a delayed manner, the initial data before the update can not be acquired by a data requester, and the data consistency between the cache data of the database and the cache data of the Redis server is effectively ensured.
In some optional implementations, step S204 includes the following steps:
and respectively acquiring first time consumption of all read requests in a preset time period corresponding to the preset items.
In this embodiment, the value of the preset time period is not specifically limited, and may be set according to an actual service usage requirement, for example, may be set within a month before the current time. The first time consumption of the read request refers to time consumption of a data reading service logic of the read request corresponding to the preset item.
And calculating the average value of all the first consumed time to obtain a second consumed time.
In this embodiment, the number of all the first consumed time may be obtained, the sum of all the first consumed time may be calculated, and then the quotient between the sum of all the first consumed time and the number of all the first consumed time may be calculated, so as to obtain the second consumed time.
And acquiring a preset time consumption value.
In this embodiment, the value of the time-consuming value is not specifically limited, and may be set according to an actual service usage requirement, for example, 500ms.
Calculating a sum between the second elapsed time and the elapsed time value.
And taking the sum as the sleep time.
In this embodiment, the sum of the second elapsed time and the elapsed time value is calculated and used as the sleep time, so as to ensure that the write request can delete the cache dirty data caused by the read request after the read request generated during the period of performing the write request corresponding to the data update operation is ended.
According to the method and the device, the first time-consuming time of all the reading requests in the preset time period corresponding to the preset items is obtained, and then the sleeping time is quickly determined based on the first time-consuming time and the preset time-consuming value, so that the follow-up process can be facilitated, the current second cache data corresponding to the target data of the Redis server can be deleted after the sleeping time, the cache dirty data caused by the reading requests can be accurately deleted, and the consistency of the database data and the cache data in the Redis server is guaranteed.
In some optional implementation manners of this embodiment, after step S205, the electronic device may further perform the following steps:
and judging whether the second cache data is failed to be deleted or not.
In this embodiment, query processing may be performed in a Redis server according to the key value corresponding to the second cache data; when no cache data corresponding to the key value is searched in the Redis server, judging that the second cache data is successfully deleted; and when cache data corresponding to the key value is inquired and obtained in the Redis server, judging that the second cache data is failed to be deleted.
And if the deletion fails, acquiring a first key value corresponding to the second cache data.
In this embodiment, when the electronic device caches target data in the database in the Redis server, a mapping relationship between the database data and the cached data is established, and the cached data corresponding to the database data can be queried from the Redis server based on the mapping relationship. Specifically, a key value, that is, a key value, of the database data in the database) may be used as a key value of the cache data corresponding to the database data in the Redis server, so as to establish a mapping relationship between the key value and the cache data based on the key values associated with the database data and the cache data. And recording the key value corresponding to the second cache data as the first key value.
And sending the first key value to a preset message queue so as to record a data deletion task corresponding to the second cache data in the message queue.
In this embodiment, the Message Queue (MQ) is a kind of data structure of "first-in first-out" in the basic data structure. In this embodiment, the message queue is used to record a data deleting task corresponding to the second cache data, that is, writing the first key value into the message queue corresponds to generating and recording a data deleting task to be executed. A confirmation character mechanism is established between the electronic equipment and the message queue, and when the message queue detects that a newly written key value exists in the queue, a confirmation character is sent to the electronic equipment. After the electronic device writes the first key value into the message queue, it may be further detected whether a confirmation character sent by the message queue is received within a preset time period. When the electronic equipment receives the confirmation character sent by the message queue within the preset time length, the first key value is judged to be successfully written into the message queue; and when the electronic equipment does not receive the confirmation character sent by the message queue within the preset time length, the first key value needs to be written into the message queue again. In addition, the value of the preset duration is not specifically limited, and may be set according to the actual use requirement, for example, may be set to 2 seconds. The successful writing of the first key value into the message queue can be ensured through the above operations.
And acquiring the first key value from the message queue.
In this embodiment, the message queue may send the first key value written therein to the electronic device according to a preset sending rule. The preset rule may be that a first key value obtaining instruction sent by the electronic device is received, or the first key value is sent to the electronic device every time a preset interval duration elapses.
And performing deletion retry processing on the second cache data obtained based on the first key value query.
In this embodiment, when the electronic device obtains the first key value in the message queue, it is determined that a data deletion task corresponding to the first key value needs to be executed currently, specifically, a target key value matching the first key value is queried from the Redis server, and corresponding target cache data, that is, second cache data corresponding to the first key value, is obtained based on the target key value. And deleting the second cache data from the Redis server after querying the second cache data.
After the dormancy time, deleting the current second cache data corresponding to the target data of the Redis server, if the deletion failure of the second cache data is detected, intelligently establishing a deletion retry mechanism for the cache data which is deleted in the Redis server, and after the updating operation is performed on the initial data stored in the database, ensuring that the cache data cached in the Redis server before the updating of the initial data can be successfully deleted, so that a data requesting party cannot acquire the initial data before the updating, and effectively ensuring the data consistency between the cache data of the database and the cache data of the Redis server.
In some optional implementations, the step of obtaining the first key value corresponding to the second cache data includes the following steps:
and starting a preset subscription program.
In this embodiment, the subscription program is a program for subscribing to a log file in a database, and the subscription program may specifically adopt a consuming component canal.
And acquiring the log file of the database based on the subscription program.
In this embodiment, when the database completes the data update, the database writes the operation information corresponding to the data update into the log file,
and acquiring an operation log from the log file.
In this embodiment, the operation log is obtained from the log file by the subscription program. The log file at least comprises the operation log, the operation log comprises operation information corresponding to data updating of the database, and the operation information comprises the first key value corresponding to the second cache data.
And acquiring the first key value corresponding to the second cache data from the operation log.
In this embodiment, after the operation log is obtained, the operation log may be analyzed based on a subscription program, and the required first key value corresponding to the second cache data may be extracted from the operation log.
According to the method and the device, the log file of the database is obtained by starting the preset subscription program, so that the first key value corresponding to the second cache data can be quickly obtained from the operation log contained in the operation log, and the subsequent deletion retry processing of the second cache data obtained by inquiring based on the first key value can be successfully and accurately carried out based on the obtained first key value.
In some optional implementations, the step of sending the first key value to a preset message queue includes the following steps:
calling a preset processing program; and the processing program is created and generated based on preset non-business codes.
In this embodiment, the non-service code is a code generated by writing based on a requirement of acquiring information transmitted by the subscription program. The non-service code is a code that does not intrude into a service line code corresponding to a preset item.
Receiving, by the processing program, the first key value transmitted by the subscribing program.
In this embodiment, the processing program may obtain the first key value from the subscription program.
Sending the first key value to the message queue based on the handler.
According to the method and the device, the processing program generated based on the preset non-business code creation is called to receive the first key value transmitted by the subscription program, and the first key value is sent to the message queue, so that the retry deletion processing of the second cache data which is failed to be deleted can not cause a great amount of invasion to the business line code, and the intelligence of the retry deletion processing of the second cache data is improved.
In some optional implementation manners of this embodiment, after the step of performing retry deletion processing on the second cache data obtained based on the keyword query, the electronic device may further perform the following steps:
and acquiring a processing result obtained after the second cache data is subjected to deletion retry processing.
In this embodiment, the processing result may include a deletion success and a deletion failure.
And judging whether the processing result is deletion failure or not.
And if so, generating alarm information corresponding to the second cache data.
In this embodiment, the alarm information may be content information including a cache service downtime of the electronic device.
And acquiring the communication information of the target user.
In this embodiment, the target user may refer to an engineer related to operation and maintenance of the database. The communication information may include a mail address or a mobile phone number of the target user.
And sending the alarm information to the user terminal of the target user based on the communication information.
In this embodiment, the warning information is sent to the user terminal of the target user, so as to prompt the target user to perform troubleshooting and repair cache service in time based on the warning information.
According to the method and the device, whether the cache service is down is effectively judged based on the obtained processing result after the second cache data is deleted and retried, corresponding alarm information can be intelligently generated when the cache service is judged to be abnormal, and related users can be prompted to repair the cache service in time through the alarm information, so that the cache data needing to be deleted can be successfully deleted, and the data consistency between the cache data of the database and the cache data of the Redis server can be guaranteed.
In some optional implementation manners of this embodiment, the method for processing cache data further includes:
and judging whether a caching request which is triggered by a second user and used for caching the specified data to the Redis server is received.
In this embodiment, the cache request carries the specified data.
If yes, setting a second key value corresponding to the designated data based on a preset lua script, and setting an expiration time corresponding to the second key value.
In this embodiment, when a cache request for caching specified data to a Redis server, which is triggered by a second user, is received, the electronic device may invoke an API interface written in a lua scripting language to request setting of a second key value corresponding to the specified data, and setting of an expiration time corresponding to the second key value. The lua script is a small scripting language, can be easily called by C/C + + codes and can also call C/C + + functions in reverse, so that the lua script can be widely applied to application programs. The lua script not only serves as an extension script, but also can serve as a common configuration file to replace XML, ini and other file formats, is easy to understand and maintain, is compiled by standard C, is concise and attractive in code, and can be compiled and run on almost all operating systems and platforms. Typically a complete lua interpreter is no more than 200k, and the speed of the lua is the fastest of all script engines. In the prior art, when the second key value is set in the Redis server, jedis is generally adopted to set a key value corresponding to the second key value first, and then the expiration time of the second key value is set in the Redis server, which is equivalent to two steps and cannot ensure the atomicity of a command. The Redis server does not execute other scripts or Redis commands when executing lua scripts, semantics are similar to MULTI (open transaction)/EXEC (trigger transaction, executing all commands in a transaction together), and from the perspective of all other clients, the effect of the script is either still invisible or has been completed. This mechanism is much like that of a relational database transaction. The Lua script operation principle is that the client can send the Lua script to the server to execute the custom action and acquire the response data of the script. The Redis server can execute the lua script in a single thread atomicity mode, and the lua script is guaranteed not to be interrupted by any other request in the processing process. Redis native does not provide atomic commands such as add and delete keys to be executed together, so that instructions for a function can only be executed with lua scripts. In this embodiment, the second key value corresponding to the specified data and the expiration time corresponding to the second key value may be directly submitted to the Redis server by using the lua script, and the two steps are performed simultaneously, so that the atomicity of the command is ensured, the network transmission is reduced, and the processing efficiency is improved.
And acquiring the specified data from the cache request.
In this embodiment, the specified data may be obtained from the cache request by performing parsing on the cache request.
Caching the specified data into the Redis server based on the second key value and the expiration time.
In this embodiment, after the second key value is successfully set in the Redis server, it indicates that the locking of the Redis server is successful, and then the specified data may be cached in the Redis server.
When a cache request for caching specified data to a Redis server triggered by a second user is received, a second key value corresponding to the specified data can be set in the Redis server in a direct submitting mode through an lua script intelligently, and expiration time corresponding to the second key value is set.
It is emphasized that, to further ensure the privacy and security of the second cache data, the second cache data may also be stored in a node of a block chain.
The block chain referred by the application is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The embodiment of the application can acquire and process related data based on an artificial intelligence technology. Among them, artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence infrastructure generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware associated with computer readable instructions, which can be stored in a computer readable storage medium, and when executed, the processes of the embodiments of the methods described above can be included. The storage medium may be a non-volatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a Random Access Memory (RAM).
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless otherwise indicated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of execution is not necessarily sequential, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
With further reference to fig. 3, as an implementation of the method shown in fig. 2, the present application provides an embodiment of a processing apparatus for caching data, where the embodiment of the apparatus corresponds to the embodiment of the method shown in fig. 2, and the apparatus may be specifically applied to various electronic devices.
As shown in fig. 3, the apparatus 300 for processing cached data according to this embodiment includes: a first judging module 301, a first deleting module 302, an updating module 303, a determining module 304 and a second deleting module 305. Wherein:
the first judging module 301 is configured to judge whether a data update operation triggered by a first user and corresponding to a database is received;
a first deleting module 302, configured to delete, if yes, a current first cache data of the Redis server;
an updating module 303, configured to update the original data in the database based on the data updating operation to obtain target data;
a determining module 304, configured to obtain time consumed by a read request corresponding to a preset item, and determine a sleep time based on the time consumed;
a second deleting module 305, configured to delete, after the sleep time elapses, second cache data that is currently corresponding to the target data of the Redis server.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In some optional implementations of this embodiment, the determining module 304 includes:
the first acquisition sub-module is used for respectively acquiring first consumed time of all the read requests in a preset time period corresponding to the preset item;
the first calculation submodule is used for calculating the average value of all the first consumed time to obtain second consumed time;
the second acquisition submodule is used for acquiring a preset time-consuming numerical value;
a second calculation submodule for calculating a sum of the second elapsed time and the elapsed time value;
a determination submodule configured to use the sum as the sleep time.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In some optional implementations of this embodiment, the processing device for caching data further includes:
the second judging module is used for judging whether the second cache data is failed to be deleted;
the first obtaining module is used for obtaining a first key value corresponding to the second cache data if the deletion fails;
the first sending module is used for sending the first key value to a preset message queue so as to record a data deleting task corresponding to the second cache data in the message queue;
a second obtaining module, configured to obtain the first key value from the message queue;
and the processing module is used for carrying out deletion retry processing on the second cache data obtained based on the first key value query.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one to one, and are not described herein again.
In some optional implementation manners of this embodiment, the first obtaining module includes:
the starting submodule is used for starting a preset subscription program;
a third obtaining sub-module, configured to obtain a log file of the database based on the subscription program;
the fourth obtaining submodule is used for obtaining an operation log from the log file;
and the fifth obtaining submodule is used for obtaining the first key value corresponding to the second cache data from the operation log.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In some optional implementations of this embodiment, the first sending module includes:
the calling sub-module is used for calling a preset processing program; the processing program is created and generated based on a preset non-business code;
the receiving submodule is used for receiving the first key value transmitted by the subscription program through the processing program;
and the sending submodule is used for sending the first key value to the message queue based on the processing program.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In some optional implementations of this embodiment, the processing device for caching data further includes:
a third obtaining module, configured to obtain a processing result obtained after performing retry deletion processing on the second cache data;
the third judging module is used for judging whether the processing result is deletion failure;
the generating module is used for generating alarm information corresponding to the second cache data if the first cache data is the first cache data;
the fourth acquisition module is used for acquiring the communication information of the target user;
and the second sending module is used for sending the alarm information to the user terminal of the target user based on the communication information.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In some optional implementations of this embodiment, the processing device for caching data further includes:
the fourth judging module is used for judging whether a caching request which is triggered by a second user and used for caching the specified data to the Redis server is received;
a setting module, configured to set a second key value corresponding to the specified data based on a preset lua script and set an expiration time corresponding to the second key value if the preset lua script is true;
a fifth obtaining module, configured to obtain the specified data from the cache request;
and the caching module is used for caching the specified data into the Redis server based on the second key value and the expiration time.
In this embodiment, the operations executed by the modules or units respectively correspond to the steps of the method for processing cache data in the foregoing embodiment one by one, and are not described herein again.
In order to solve the technical problem, an embodiment of the present application further provides a computer device. Referring to fig. 4, fig. 4 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only computer device 4 having components 41-43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including flash memory, hard disks, multimedia cards, card-type memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), programmable Read Only Memory (PROM), magnetic memory, magnetic disks, optical disks, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system installed in the computer device 4 and various types of application software, such as computer readable instructions of a processing method for caching data. Further, the memory 41 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute the computer readable instructions stored in the memory 41 or process data, for example, execute the computer readable instructions of the processing method of the cache data.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing communication connection between the computer device 4 and other electronic devices.
Compared with the prior art, the embodiment of the application mainly has the following beneficial effects:
in the embodiment of the application, when a data updating operation triggered by a first user and corresponding to a database is received, current first cache data of a Redis server is deleted, then original data in the database is updated based on the data updating operation to obtain target data, time consumed by a reading request corresponding to a preset item is obtained subsequently, dormancy time is determined based on the time consumed, and finally second cache data corresponding to the target data of the Redis server is deleted after the dormancy time elapses. According to the embodiment of the application, after the initial data stored in the database is updated, the dormancy time is determined based on the time consumed by the read request corresponding to the preset item, and then the current cache data of the Redis server is deleted according to the dormancy time, so that the cache data cached in the Redis server before the initial data is updated is deleted in a delayed manner, a data requester cannot acquire the initial data before the update, and the data consistency between the cache data of the database and the cache data of the Redis server is effectively ensured. .
The present application further provides another embodiment, which is to provide a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, which can be executed by at least one processor, so as to cause the at least one processor to execute the steps of the method for processing the cache data.
Compared with the prior art, the embodiment of the application mainly has the following beneficial effects:
in the embodiment of the application, when a data updating operation triggered by a first user and corresponding to a database is received, current first cache data of a Redis server is deleted, then original data in the database is updated based on the data updating operation to obtain target data, time consumed by a reading request corresponding to a preset item is obtained subsequently, dormancy time is determined based on the time consumed, and finally second cache data corresponding to the target data of the Redis server is deleted after the dormancy time elapses. According to the embodiment of the application, after the initial data stored in the database is updated, the dormancy time is determined based on the time consumed by the read request corresponding to the preset item, and then the current cache data of the Redis server is deleted according to the dormancy time, so that the cache data cached in the Redis server before the initial data is updated is deleted in a delayed manner, a data requester cannot acquire the initial data before the update, and the data consistency between the cache data of the database and the cache data of the Redis server is effectively ensured.
Through the description of the foregoing embodiments, it is clear to those skilled in the art that the method of the foregoing embodiments may be implemented by software plus a necessary general hardware platform, and certainly may also be implemented by hardware, but in many cases, the former is a better implementation. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
It is to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields and are within the protection scope of the present application.

Claims (10)

1. A processing method for caching data is characterized by comprising the following steps:
judging whether a data updating operation triggered by a first user and corresponding to a database is received;
if so, deleting the current first cache data of the Redis server;
updating the original data in the database based on the data updating operation to obtain target data;
acquiring time consumed by a reading request corresponding to a preset project, and determining sleep time based on the time consumed;
and after the dormancy time, deleting the current second cache data corresponding to the target data of the Redis server.
2. The method for processing cached data according to claim 1, wherein the step of obtaining a time consumed by the read request corresponding to the preset item and determining the sleep time based on the time consumed specifically comprises:
respectively acquiring first consumed time of all read requests in a preset time period corresponding to the preset item;
calculating the average value of all the first consumed time to obtain second consumed time;
acquiring a preset time consumption value;
calculating a sum between the second elapsed time and the elapsed time value;
and taking the sum value as the sleep time.
3. The method for processing cached data as claimed in claim 1, wherein after the step of deleting the second cached data corresponding to the target data currently by the Redis server after the sleep time elapses, the method further comprises:
judging whether the second cache data is failed to be deleted or not;
if the deletion fails, acquiring a first key value corresponding to the second cache data;
sending the first key value to a preset message queue so as to record a data deletion task corresponding to the second cache data in the message queue;
acquiring the first key value from the message queue;
and performing deletion retry processing on the second cache data obtained based on the first key value query.
4. The method for processing cached data according to claim 3, wherein the step of obtaining the first key value corresponding to the second cached data specifically comprises:
starting a preset subscription program;
acquiring a log file of the database based on the subscription program;
acquiring an operation log from the log file;
and acquiring the first key value corresponding to the second cache data from the operation log.
5. The method for processing cached data according to claim 4, wherein the step of sending the first key value to a preset message queue specifically comprises:
calling a preset processing program; the processing program is created and generated based on a preset non-business code;
receiving, by the handler, the first key value transmitted by the subscribing program;
sending the first key value to the message queue based on the handler.
6. The method for processing cached data as claimed in claim 3, further comprising, after said step of performing a retry of deletion on said second cached data obtained based on said keyword query:
obtaining a processing result obtained after the second cache data is subjected to deletion retry processing;
judging whether the processing result is deletion failure or not;
if so, generating alarm information corresponding to the second cache data;
acquiring communication information of a target user;
and sending the alarm information to the user terminal of the target user based on the communication information.
7. The method for processing the cached data as claimed in claim 1, further comprising:
judging whether a caching request which is triggered by a second user and used for caching specified data to the Redis server is received;
if yes, setting a second key value corresponding to the specified data based on a preset lua script, and setting an expiration time corresponding to the second key value;
acquiring the specified data from the cache request;
caching the specified data into the Redis server based on the second key value and the expiration time.
8. A processing apparatus for caching data, comprising:
the first judgment module is used for judging whether data updating operation which is triggered by a first user and corresponds to the database is received or not;
the first deleting module is used for deleting the current first cache data of the Redis server if the first cache data of the Redis server is the current first cache data of the Redis server;
the updating module is used for updating the original data in the database based on the data updating operation to obtain target data;
the determining module is used for acquiring the time consumed by the reading request corresponding to the preset item and determining the sleeping time based on the time consumed;
and the second deleting module is used for deleting the second cache data corresponding to the target data currently by the Redis server after the dormancy time.
9. A computer device comprising a memory having computer readable instructions stored therein and a processor which when executed implements the steps of a method of processing cached data as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, having computer-readable instructions stored thereon, which, when executed by a processor, implement the steps of the method of processing cached data as recited in any one of claims 1 to 7.
CN202211153999.4A 2022-09-21 2022-09-21 Cache data processing method and device, computer equipment and storage medium Pending CN115455058A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211153999.4A CN115455058A (en) 2022-09-21 2022-09-21 Cache data processing method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211153999.4A CN115455058A (en) 2022-09-21 2022-09-21 Cache data processing method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115455058A true CN115455058A (en) 2022-12-09

Family

ID=84307569

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211153999.4A Pending CN115455058A (en) 2022-09-21 2022-09-21 Cache data processing method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115455058A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116886964A (en) * 2023-09-05 2023-10-13 深圳市华曦达科技股份有限公司 OTT content timing release and update processing method and device
CN117270794A (en) * 2023-11-22 2023-12-22 成都大成均图科技有限公司 Redis-based data storage method, medium and device

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116886964A (en) * 2023-09-05 2023-10-13 深圳市华曦达科技股份有限公司 OTT content timing release and update processing method and device
CN116886964B (en) * 2023-09-05 2023-12-22 深圳市华曦达科技股份有限公司 OTT content timing release and update processing method and device
CN117270794A (en) * 2023-11-22 2023-12-22 成都大成均图科技有限公司 Redis-based data storage method, medium and device
CN117270794B (en) * 2023-11-22 2024-02-23 成都大成均图科技有限公司 Redis-based data storage method, medium and device

Similar Documents

Publication Publication Date Title
WO2019140828A1 (en) Electronic apparatus, method for querying logs in distributed system, and storage medium
CN115455058A (en) Cache data processing method and device, computer equipment and storage medium
CN112162965B (en) Log data processing method, device, computer equipment and storage medium
CN108287708B (en) Data processing method and device, server and computer readable storage medium
CN112380227B (en) Data synchronization method, device, equipment and storage medium based on message queue
CN115757495A (en) Cache data processing method and device, computer equipment and storage medium
CN113254445B (en) Real-time data storage method, device, computer equipment and storage medium
CN112199442B (en) Method, device, computer equipment and storage medium for distributed batch downloading files
CN111651296A (en) Interception backup method, device, equipment and storage medium for data deletion operation
US20220245208A1 (en) Method for switching skin of mini-program page, and electronic device
CN107657155B (en) Method and device for authenticating user operation authority
CN112363814A (en) Task scheduling method and device, computer equipment and storage medium
CN111475388A (en) Data push test method and device, computer equipment and storage medium
CN115062084B (en) Method and device for constructing API (application programming interface) based on database metadata
CN111475468A (en) Log access method, device, equipment and storage medium of newly added system
CN114218191A (en) System function migration method and device, computer equipment and storage medium
CN117194496A (en) Data batch request method and device, computer equipment and storage medium
CN116775649A (en) Data classified storage method and device, computer equipment and storage medium
CN115834685A (en) Screen adaptation method based on dynamic proxy and related equipment thereof
CN117332012A (en) Data association method, device, equipment and storage medium thereof
CN115562662A (en) Application page creating method and device, computer equipment and storage medium
CN115686793A (en) Scheduling method, scheduling device, computer equipment and storage medium
CN117873831A (en) SQL performance monitoring method, SQL performance monitoring device, SQL performance monitoring computer equipment and SQL performance storage medium
CN115827047A (en) Request processing method and device, computer equipment and storage medium
CN116302036A (en) Business parameter management method, device, equipment and storage medium based on micro-service

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