Disclosure of Invention
In view of this, embodiments of the present application provide a data updating method, an apparatus, a terminal device, and a storage medium, so as to solve the problem that, in the data updating process in the prior art, when data replacement of local data by data to be updated is wrong, both the local data and the data to be updated cannot normally provide data using services.
A first aspect of an embodiment of the present application provides a data updating method, including:
receiving a data updating prompt sent by an updating database, and setting data pointed by the data updating prompt in the updating database as data to be updated;
acquiring a data caching rule of the data to be updated, and locally caching the data to be updated according to the acquired data caching rule to obtain cached data;
if the local cache result of the cache data meets the data updating condition, acquiring a data analysis rule of the data to be updated;
and performing data analysis on the cache data according to the obtained data analysis rule to obtain effective data, and performing data updating on local data according to the effective data.
Further, the obtaining a data caching rule of the data to be updated, and locally caching the data to be updated according to the obtained data caching rule to obtain cached data includes:
acquiring format information of the data to be updated, and setting a data type pointed by the format information as the data type of the data to be updated;
setting information pointed by the data type of the data to be updated as the data cache rule of the data to be updated, and acquiring a data cache path, a data cache format, a data cache speed and a data call interface pointed by the data cache rule;
and locally caching the data to be updated by the acquired data caching path, the data caching format, the data caching speed and the data calling interface to obtain the cached data.
Further, after the locally caching the data to be updated according to the obtained data caching rule to obtain cached data, the method further includes:
acquiring data information of the cache data, wherein the data information comprises at least one parameter information, and the parameter information is format information, paragraph information or data volume information;
comparing the parameter information in the data information with corresponding preset information;
if any parameter information in the data information is not matched with the corresponding preset information, judging that a local cache result of the cache data does not meet the data updating condition;
and if the parameter information in the data information is matched with the corresponding preset information, judging that the local cache result of the cache data meets the data updating condition.
Further, the data analysis of the cache data according to the obtained data analysis rule to obtain valid data includes:
performing text translation on the cache data to obtain a data text, and compiling a data analysis object by using a regular expression preset in the data analysis rule;
performing text search and/or replacement on the data text by using a text processing rule pointed by the data analysis object to obtain a text processing result, wherein the text processing result comprises at least one target position, and the target position is a data position of the corresponding effective data in the cache data;
and taking the target position as a data extraction position to extract the data of the cache data to obtain the effective data.
Further, after performing data analysis on the cached data according to the obtained data analysis rule to obtain valid data, the method further includes:
acquiring a data tag of the data to be updated, setting data pointed by the data tag in local data as target data of the data to be updated, wherein the target data and the data to be updated provide the same data use service;
respectively calculating hash values of the target data and the effective data to obtain a target hash value and an effective hash value;
and if the target hash value is equal to the effective hash value, sending an update error prompt aiming at the data to be updated.
Further, after the data updating is performed on the local data according to the valid data, the method further includes:
acquiring a prompt identifier of the data updating prompt, and setting a data issuing table pointed by the prompt identifier as a data issuing table of the updating database, wherein the data issuing table stores corresponding relations between different communication addresses and corresponding associated clients;
acquiring a local communication address, issuing the local communication address and the data of the update database for matching, and acquiring the associated client corresponding to the data update prompt;
acquiring a storage address of the data to be updated in the update database, and generating a data update broadcast by the storage address;
and broadcasting the data updating broadcast to the matched associated client for notification.
Further, after the locally caching the data to be updated according to the obtained data caching rule to obtain cached data, the method further includes:
if the local cache result of the cache data does not meet the data updating condition, the prompt identifier of the data updating prompt inquires the data of the updating database and issues the data;
acquiring a local communication address, and matching the local communication address with the inquired data published list to obtain an associated client corresponding to the data updating prompt;
acquiring the update state of the associated client aiming at the data to be updated;
and if the update state of the data to be updated on any one of the associated clients is the updated state, locally caching the data to be updated again until the local caching result of the cached data meets the data updating condition.
A second aspect of an embodiment of the present application provides a data updating apparatus, including:
the data query unit is used for receiving a data update prompt sent by an update database and setting data pointed by the data update prompt in the update database as data to be updated;
the local cache unit is used for acquiring a data cache rule of the data to be updated and locally caching the data to be updated according to the acquired data cache rule to obtain cache data;
the analysis rule obtaining unit is used for obtaining a data analysis rule of the data to be updated if a local cache result of the cache data meets a data updating condition;
and the data updating unit is used for performing data analysis on the cache data according to the obtained data analysis rule to obtain effective data, and performing data updating on local data according to the effective data.
A third aspect of the embodiments of the present application provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the terminal device, where the processor implements the steps of the data updating method provided by the first aspect when executing the computer program.
A fourth aspect of the embodiments of the present application provides a storage medium, which stores a computer program that, when executed by a processor, implements the steps of the data updating method provided by the first aspect.
The data updating method, the data updating device, the terminal equipment and the storage medium provided by the embodiment of the application have the following beneficial effects:
according to the data updating method provided by the embodiment of the application, the data caching rule of the data to be updated is obtained, the obtained data caching rule is used for locally caching the data to be updated, data damage caused by data replacement of the local data is prevented, the data service can be normally provided for the local data when the data updating is wrong, the data analysis rule of the data to be updated is obtained, the obtained data analysis rule is used for carrying out data analysis on the cached data, effective data in the cached data can be effectively extracted, the local data is updated based on the extracted effective data, the effect of data hot updating is achieved, and the data updating efficiency is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The data updating method according to the embodiment of the present application may be executed by a control device or a terminal (hereinafter referred to as a "mobile terminal").
Referring to fig. 1, fig. 1 shows a flowchart of an implementation of a data updating method provided in an embodiment of the present application, including:
step S10, receiving a data update prompt sent by the update database, and setting data pointed by the data update prompt in the update database as data to be updated.
The data updating method can be applied to any mobile terminal, the updating database is a database preset for the mobile terminal, the mobile terminal and the updating database can store corresponding relations in a one-to-many mode, and the updating database is used for sending a data updating prompt to the mobile terminal and providing corresponding data to be updated when data updating occurs.
For example, the update database corresponding to the mobile terminal comprises an update database a1, an update database a2 and an update database a3, and when the update database a1 has data update, the update database a1 sends a data update prompt to the mobile terminal.
Specifically, in this step, a data lookup table is stored in the update database, and a corresponding relationship between different data identifiers and corresponding data is stored in the data lookup table, so that the data pointed by the data update prompt in the update database is obtained by matching the data identifiers stored in the data update prompt with the data lookup table.
Step S20, obtaining a data caching rule of the data to be updated, and locally caching the data to be updated according to the obtained data caching rule to obtain cached data.
Specifically, in this step, the obtaining a data caching rule of the data to be updated, and locally caching the data to be updated according to the obtained data caching rule to obtain cached data includes:
the format information of the data to be updated is acquired, and the data type pointed by the format information is set as the data type of the data to be updated, wherein a data type query table is prestored in the embodiment, and the data type query table stores the corresponding relationship between different format information and the corresponding data type, so that the data type pointed by the format information is obtained by matching the format information of the data to be updated with the data type query table.
Setting information pointed by the data type of the data to be updated as the data cache rule of the data to be updated, and obtaining a data cache path, a data cache format, a data cache speed and a data call interface pointed by the data cache rule, wherein a rule lookup table is prestored in the embodiment, and the rule lookup table stores corresponding relations between different data cache rules and corresponding data cache paths, data cache formats, data cache speeds and data call interfaces.
And locally caching the data to be updated according to the acquired data caching path, the acquired data caching format, the acquired data caching speed and the acquired data calling interface to obtain the cached data, wherein caching of the data to be updated in the local data is effectively guaranteed based on the data caching path, format conversion is performed on the data to be updated based on the data caching format, unification of the data format after caching of the data to be updated is effectively guaranteed, caching efficiency in the caching process of the data to be updated is effectively guaranteed based on the data caching speed, and data calling after caching of the data to be updated is effectively guaranteed based on the data calling interface.
Step S30, if the local cache result of the cache data meets the data update condition, obtaining the data analysis rule of the data to be updated.
The data updating condition is used for judging whether a local cache result of the cache data is abnormal or not, if the local cache result of the cache data meets the data updating condition, the local cache operation of the data to be updated is judged to be normal, and the cache data obtained by caching is correct.
Specifically, in this embodiment, an analysis rule lookup table is prestored, and a corresponding relationship between different databases and corresponding data analysis rules is stored in the analysis rule lookup table, so that the data analysis rule of the data to be updated is obtained by matching the update database corresponding to the data to be updated with the analysis rule lookup table, and the data analysis rule is used for performing data analysis on the data to be updated to obtain valid data in the data to be updated.
Optionally, in this embodiment, if the local caching result of the cached data does not satisfy the data updating condition, an update error prompt is sent for the data to be updated.
Step S40, performing data analysis on the cache data according to the obtained data analysis rule to obtain valid data, and performing data update on local data according to the valid data.
Specifically, in this step, the performing data analysis on the cache data according to the obtained data analysis rule to obtain valid data includes:
the cache data is subjected to text translation to obtain a data text, and a regular expression preset in the data analysis rule is compiled into a data analysis object, wherein the text translation of the cache data can be performed in a text translator mode, and the text translation is used for converting the cache data into a text format, so that the subsequent text processing operation of the cache data is effectively facilitated.
And performing text search and/or replacement on the data text according to a text processing rule pointed by the data analysis object to obtain a text processing result, wherein the text search and/or replacement can be performed on the data text according to the data analysis object, so that the position of effective data in the cache data can be effectively identified, the text processing result comprises at least one target position, the target position is the data position of the corresponding effective data in the cache data, and the target position can be a character string position, a character position, a field position or the like.
And taking the target position as a data extraction position to extract the data of the cache data to obtain the effective data.
Optionally, in this step, after performing data analysis on the cached data according to the obtained data analysis rule to obtain valid data, the method further includes:
and acquiring a data tag of the data to be updated, and setting data pointed by the data tag in local data as target data of the data to be updated, wherein the target data and the data to be updated provide the same data use service, and the target data is data which needs to be updated on the mobile terminal.
Respectively calculating hash values of the target data and the effective data to obtain a target hash value and an effective hash value, and comparing the target hash value with the effective hash value, wherein the target hash value and the effective hash value are compared to judge whether the effective data and the target data are the same data;
and if the target hash value is equal to the effective hash value, sending an update error prompt aiming at the data to be updated, wherein if the target hash value is equal to the effective hash value, judging that the effective data and the target data are the same data, namely the data to be updated is updated on the mobile terminal in an error manner, and sending the update error prompt aiming at the data to be updated so as to prompt a user to perform manual inquiry and detection.
In the embodiment, the data cache rule of the data to be updated is obtained, and the obtained data cache rule is used for locally caching the data to be updated, so that data damage caused by data replacement of the local data is prevented, and the data service can be normally provided by the local data when the data update is wrong.
Referring to fig. 2, fig. 2 is a flowchart illustrating an implementation of a data updating method according to another embodiment of the present application. With respect to the embodiment corresponding to fig. 1, the data updating method provided in this embodiment further includes, after step S20 of fig. 1:
step S50, acquiring data information of the cached data, and performing information comparison between the parameter information in the data information and corresponding preset information.
The data information comprises at least one piece of parameter information, the parameter information is format information, paragraph information or data volume information, the preset information comprises preset format information, preset paragraph information and preset data volume information, the preset format information, the preset paragraph information and the preset data volume information can be set according to requirements, and the format information, the paragraph information and the data volume information in the data information corresponding to the cache data are compared with the preset format information, the preset paragraph information and the preset data volume information respectively to judge whether the cache data are cached correctly.
Step S60, if any of the parameter information in the data information does not match the corresponding preset information, determining that the local caching result of the cached data does not satisfy the data updating condition.
If the format information of the cached data is not matched with the preset format information, it is determined that the storage format of the cached data has an error, the cached data cannot perform effective data update on the mobile terminal, if the paragraph information of the cached data is not matched with the preset paragraph information, it is determined that the paragraph information of the cached data has an error, the cached data cannot perform effective data update on the mobile terminal, if the data amount information of the cached data is not matched with the preset data amount information, it is determined that the data amount of the cached data has an error, the cached data cannot perform effective data update on the mobile terminal, that is, the local cached result of the cached data does not satisfy the data update condition.
Step S70, if the parameter information in the data information matches the corresponding preset information, it is determined that the local caching result of the cached data satisfies the data updating condition.
If the format information, the paragraph information and the data volume information of the cached data are all matched with the preset format information, the preset paragraph information and the preset data volume information, it is determined that the local caching operation of the data to be updated is normal, and the cached data obtained by caching is correct.
In the embodiment, by acquiring the data information of the cache data and comparing the parameter information in the data information with the corresponding preset information, the local cache operation of the data to be updated can be effectively judged to be normal, and whether the cache data obtained by caching is correct or not can be effectively judged, so that the accuracy of data updating is improved.
Referring to fig. 3, fig. 3 is a flowchart illustrating an implementation of a data updating method according to another embodiment of the present application. With respect to the embodiment corresponding to fig. 1, the data updating method provided in this embodiment further includes, after step S40 of fig. 1:
step S80, obtaining a prompt identifier of the data update prompt, and setting the data publishing table pointed by the prompt identifier as the data publishing table of the update database.
The implementation is pre-stored with a data issuing query table, and the data issuing query table stores the corresponding relationship between different prompt identifiers and corresponding data issuing tables.
In this step, the prompt identifier of the data update prompt is matched with the data issuance query table to obtain the data issuance statement pointed by the prompt identifier, and the data issuance statement stores the corresponding relationship between different communication addresses and corresponding associated clients.
And step S90, obtaining a local communication address, and issuing and matching the local communication address with the data of the update database to obtain the associated client corresponding to the data update prompt.
The associated client and the mobile terminal corresponding to the data update prompt are devices in the same update queue, that is, both the associated client and the mobile terminal need to update data to be updated corresponding to the data update prompt.
For example, when the local communication address is matched with the published data obtained by querying and the associated client b1 and the associated client b2 are obtained, it is determined that the associated client b1 and the associated client b2 need to update the data to be updated corresponding to the data update prompt.
Step S100, obtaining the storage address of the data to be updated in the update database, and generating a data update broadcast by the storage address.
The method comprises the steps of obtaining a storage address of data to be updated in an update database, effectively improving the accuracy of data update broadcast generation, and generating the data update broadcast by the storage address, so that the storage address of the data to be updated in the update database can be effectively stored in the data update broadcast.
Step S110, performing broadcast notification on the matched associated client by the data update broadcast.
The matched associated client is broadcasted by the data updating broadcast, so that the effect of prompting the associated client to synchronously update the data is achieved.
Specifically, in this step, a data update broadcast carrying the storage address of the data to be updated is used to perform broadcast notification on the matched associated client, so as to prompt the matched associated client to download and update data based on the storage address of the data to be updated.
Further, in this embodiment, after locally caching the data to be updated according to the obtained data caching rule to obtain cached data, the method further includes:
if the local cache result of the cache data does not meet the data updating condition, the prompt identifier of the data updating prompt inquires the data of the updating database and issues the data;
acquiring a local communication address, and matching the local communication address with the inquired data published list to obtain an associated client corresponding to the data updating prompt;
acquiring the update state of the associated client aiming at the data to be updated;
if the update state of the data to be updated on any one of the associated clients is the updated state, locally caching the data to be updated again until the local caching result of the cached data meets the data updating condition;
if the update state of the data to be updated on any associated client is the updated state, judging that the data to be updated is not abnormal, wherein the fact that the local cache result of the cache data on the mobile terminal does not meet the data update condition is caused by cache error and is not caused by the abnormality of the data to be updated, so that the effect of updating the data again is achieved by performing local cache on the data to be updated, and the accuracy of updating the data is improved.
In the embodiment, the prompt identifier of the data updating prompt is obtained, the data publishing table pointed by the prompt identifier is set as the data publishing table of the updating database, the query accuracy of the associated client is effectively improved, the associated client corresponding to the mobile terminal is obtained by matching the local communication address with the queried data publishing table, the storage address of the data to be updated in the updating database is obtained, the generation accuracy of the data updating broadcast is improved, the data updating broadcast is generated by the storage address, the storage address of the data to be updated in the updating database can be effectively stored in the data updating broadcast, and the matched associated client is broadcasted and notified by the data updating broadcast, so that the effect of prompting the associated client to synchronously update the data is achieved.
In all embodiments of the present application, the cache data is subjected to data analysis based on the obtained data analysis rule to obtain valid data, and specifically, the valid data is obtained by performing data analysis on the cache data according to the obtained data analysis rule. Uploading valid data to the blockchain can ensure the safety and the fair transparency to users. The user equipment may download the valid data from the blockchain to verify whether the valid data is tampered. The blockchain referred to in this example is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, 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.
Referring to fig. 4, fig. 4 is a block diagram of a data updating apparatus 100 according to an embodiment of the present disclosure. The data updating apparatus 100 in this embodiment includes units for executing steps in the embodiments corresponding to fig. 1, fig. 2, and fig. 3. Please refer to fig. 1, fig. 2, and fig. 3, and the corresponding embodiments of fig. 1, fig. 2, and fig. 3. For convenience of explanation, only the portions related to the present embodiment are shown. Referring to fig. 4, the data update apparatus 100 includes: data query unit 10, local cache unit 11, parsing rule obtaining unit 12 and data updating unit 13, wherein:
the data query unit 10 is configured to receive a data update prompt sent by an update database, and set data pointed by the data update prompt in the update database as data to be updated.
The local caching unit 11 is configured to obtain a data caching rule of the data to be updated, and locally cache the data to be updated according to the obtained data caching rule to obtain cached data.
Wherein, the local cache unit 10 is further configured to:
acquiring format information of the data to be updated, and setting a data type pointed by the format information as the data type of the data to be updated;
setting information pointed by the data type of the data to be updated as the data cache rule of the data to be updated, and acquiring a data cache path, a data cache format, a data cache speed and a data call interface pointed by the data cache rule;
and locally caching the data to be updated by the acquired data caching path, the data caching format, the data caching speed and the data calling interface to obtain the cached data.
Optionally, the local cache unit 10 is further configured to:
acquiring data information of the cache data, wherein the data information comprises at least one parameter information, and the parameter information is format information, paragraph information or data volume information;
comparing the parameter information in the data information with corresponding preset information;
if any parameter information in the data information is not matched with the corresponding preset information, judging that a local cache result of the cache data does not meet the data updating condition;
and if the parameter information in the data information is matched with the corresponding preset information, judging that the local cache result of the cache data meets the data updating condition.
Further, the local cache unit 10 is further configured to:
if the local cache result of the cache data does not meet the data updating condition, the prompt identifier of the data updating prompt inquires the data of the updating database and issues the data;
acquiring a local communication address, and matching the local communication address with the inquired data published list to obtain an associated client corresponding to the data updating prompt;
acquiring the update state of the associated client aiming at the data to be updated;
and if the update state of the data to be updated on any one of the associated clients is the updated state, locally caching the data to be updated again until the local caching result of the cached data meets the data updating condition.
An analysis rule obtaining unit 12, configured to obtain a data analysis rule of the data to be updated if a local cache result of the cache data meets a data update condition.
And the data updating unit 13 is configured to perform data analysis on the cache data according to the obtained data analysis rule to obtain valid data, and perform data updating on local data according to the valid data.
Wherein, the data updating unit 13 is further configured to: performing text translation on the cache data to obtain a data text, and compiling a data analysis object by using a regular expression preset in the data analysis rule;
performing text search and/or replacement on the data text by using a text processing rule pointed by the data analysis object to obtain a text processing result, wherein the text processing result comprises at least one target position, and the target position is a data position of the corresponding effective data in the cache data;
and taking the target position as a data extraction position to extract the data of the cache data to obtain the effective data.
Optionally, the data updating unit 13 is further configured to: acquiring a data tag of the data to be updated, setting data pointed by the data tag in local data as target data of the data to be updated, wherein the target data and the data to be updated provide the same data use service;
respectively calculating hash values of the target data and the effective data to obtain a target hash value and an effective hash value;
and if the target hash value is equal to the effective hash value, sending an update error prompt aiming at the data to be updated.
Further, the data updating unit 13 is further configured to: acquiring a prompt identifier of the data updating prompt, and setting a data issuing table pointed by the prompt identifier as a data issuing table of the updating database, wherein the data issuing table stores corresponding relations between different communication addresses and corresponding associated clients;
acquiring a local communication address, issuing the local communication address and the data of the update database for matching, and acquiring the associated client corresponding to the data update prompt;
acquiring a storage address of the data to be updated in the update database, and generating a data update broadcast by the storage address;
and broadcasting the data updating broadcast to the matched associated client for notification.
In the embodiment, the data cache rule of the data to be updated is obtained, and the obtained data cache rule is used for locally caching the data to be updated, so that data damage caused by data replacement of the local data is prevented, and the data service can be normally provided by the local data when the data update is wrong.
Fig. 5 is a block diagram of a terminal device 2 according to another embodiment of the present application. As shown in fig. 5, the terminal device 2 of this embodiment includes: a processor 20, a memory 21 and a computer program 22, such as a program of a data update method, stored in said memory 21 and executable on said processor 20. The processor 20, when executing the computer program 23, implements the steps in the embodiments of the data updating methods described above, such as S10 to S40 shown in fig. 1, or S50 to S70 shown in fig. 2, or S80 to S120 shown in fig. 3. Alternatively, when the processor 20 executes the computer program 22, the functions of the units in the embodiment corresponding to fig. 4, for example, the functions of the units 10 to 13 shown in fig. 4, are implemented, for which reference is specifically made to the relevant description in the embodiment corresponding to fig. 5, which is not repeated herein.
Illustratively, the computer program 22 may be divided into one or more units, which are stored in the memory 21 and executed by the processor 20 to accomplish the present application. The one or more units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of the computer program 22 in the terminal device 2. For example, the computer program 22 may be divided into the data query unit 10, the local cache unit 11, the parsing rule obtaining unit 12 and the data update unit 13, and the specific functions of each unit are as described above.
The terminal device may include, but is not limited to, a processor 20, a memory 21. It will be appreciated by those skilled in the art that fig. 5 is merely an example of a terminal device 2 and does not constitute a limitation of the terminal device 2 and may include more or less components than those shown, or some components may be combined, or different components, for example the terminal device may also include input output devices, network access devices, buses, etc.
The Processor 20 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 21 may be an internal storage unit of the terminal device 2, such as a hard disk or a memory of the terminal device 2. The memory 21 may also be an external storage device of the terminal device 2, 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, which are provided on the terminal device 2. Further, the memory 21 may also include both an internal storage unit and an external storage device of the terminal device 2. The memory 21 is used for storing the computer program and other programs and data required by the terminal device. The memory 21 may also be used to temporarily store data that has been output or is to be output.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.