Data query method and device and electronic equipment

By storing target data in two databases with high read and write speeds and using the storage time of the second database to determine the query results when the query fails, the problem that a single database cannot take into account both query efficiency and reliability is solved, and the technical effect of improving the reliability of database data is achieved.

CN119829591APending Publication Date: 2025-04-15CHINA TELECOM BESTPAY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411832493.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2025-04-15

AI Technical Summary

Technical Problem

In the prior art, a single database cannot take into account both data query efficiency and query performance, resulting in problems such as network congestion, system crashes and data loss, and there are problems with unsatisfactory data reliability.

Method used

By obtaining the target data, and performing storage processing in a first database with a higher read and write speed (such as Redis) and a second database with a lower read and write speed (such as Mysql) respectively. In response to the query request, if the first database query fails and the second database has target data, the query result is determined based on the storage time in the second database.

Benefits of technology

It realizes the use of different types of databases for data backup, improves the reliability and query consistency of data in the database, and avoids data loss problems caused by operational errors and system crashes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119829591A_ABST
    Figure CN119829591A_ABST
Patent Text Reader

Abstract

The invention discloses a data query method and device and electronic equipment. The method comprises the following steps: acquiring target data; based on the target data, storage processing to a first database and a second database is executed respectively, and the read-write speed of the first database is higher than that of the second database; and in response to a query request for the target data, determining a query result of the query request based on the first storage duration of the target data in the second database under the conditions that the first query state of the first database is query failure and the second query state of the second database is existence of the target data. The technical problem that the reliability of data in a database is not ideal in the prior art is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of software development, and in particular to a data query method, device and electronic device. Background Art

[0002] The efficiency and reliability of data query and storage are the key to ensuring smooth business operations. With the continuous development of technologies such as the Internet of Things, cloud computing, big data, and artificial intelligence, the rapid growth of data volume has become an inevitable trend. The surge in the number of users and the explosive growth in data volume have put forward higher requirements for data storage systems, including high-speed data reading and writing, data integrity, and reliability. The related technologies use a single database to perform data storage and query, which cannot take into account both data query efficiency and query performance. The large amount of query data and the large number of querying people may lead to network congestion, system crashes, and data loss, and there is a problem of being unable to guarantee data reliability.

[0003] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention

[0004] The embodiments of the present application provide a data query method, device and electronic device to at least solve the technical problem of unsatisfactory data reliability in the database existing in the related art.

[0005] According to one aspect of an embodiment of the present application, a data query method is provided, including: acquiring target data; based on the target data, performing storage processing to a first database and a second database respectively, wherein the read and write speeds of the first database are greater than the read and write speeds of the second database; in response to a query request for the target data, when a first query status of the first database is query failure and a second query status of the second database is the existence of the target data, determining a query result of the query request based on a first storage duration of the target data in the second database.

[0006] Optionally, based on the target data, storage processing is performed in the first database and the second database respectively, including: determining the storage time of obtaining the target data; generating storage information including the data name, data value, and storage time of the target data; and storing the storage information in the first database and the second database respectively.

[0007] Optionally, based on the first storage duration of the target data in the second database, the query result of the query request is determined, including: determining the first storage duration according to the storage time indicated by the storage information and the current time; when the first storage duration is less than a predetermined duration threshold, determining the data value of the target data stored in the second database as the query result.

[0008] Optionally, the second database is provided with a query switch, and the method further includes: determining application requirements for the target data; when the application requirement is that the priority of query delay is greater than the priority of data reliability, determining that the query switch is in a closed state, wherein the second database with the query switch in the closed state prohibits the execution of a data query function; when the application requirement is that the priority of data reliability is greater than the priority of query delay, determining that the query switch is in an open state, wherein the second database with the query switch in the open state allows the execution of a data query function.

[0009] Optionally, after performing storage processing on the first database and the second database respectively based on the target data, the method further includes: determining a first storage result of the storage processing performed by the first database, and a second storage result of the storage processing performed by the second database; in the event that either the first storage result or the second storage result is a storage failure, performing data rollback processing on the first database and the second database respectively, wherein the data rollback processing is used to delete the storage processing based on the target data.

[0010] Optionally, based on the target data, storage processing is performed on the first database and the second database respectively, including: determining the data name, data value, and storage information of the storage time including the target data; detecting whether the first information exists in the first database, wherein the first name included in the first information is the same as the data name, and the first value included in the first information is the same as the data value; if the first information exists in the first database, updating the first moment included in the first information to the storage moment as storage processing for the first database; updating the second moment included in the second information existing in the second database to the storage moment as storage processing for the second database, wherein the second information matches the first information.

[0011] Optionally, the method also includes: determining a target time period in which the amount of data responded by the first database is less than a predetermined data amount threshold; in the target time period, comparing the data stored in the first database with the data stored in the second database to obtain a comparison result; when the comparison result indicates that there is a data deviation between the first database and the second database, and the operating status of the first database is normal, adjusting the data stored in the second database according to the data stored in the first database.

[0012] Optionally, the method also includes: when the first query status of the first database is a successful query, determining the second storage duration of the target data in the first database; when the second storage duration is less than a predetermined duration threshold, determining the data value of the target data stored in the first database as the query result.

[0013] According to another aspect of an embodiment of the present application, a data query device is provided, including: a target data acquisition module, used to acquire target data; a storage module, used to perform storage processing to a first database and a second database, respectively, based on the target data, wherein the read and write speeds of the first database are greater than the read and write speeds of the second database; a query module, used to respond to a query request for target data, when a first query status of the first database is query failure and a second query status of the second database is the existence of target data, determine a query result of the query request based on a first storage duration of the target data in the second database.

[0014] According to another aspect of an embodiment of the present application, an electronic device is provided, comprising: one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by one or more processors, the one or more processors implement any one of the data query methods.

[0015] In the embodiment of the present application, by acquiring the target data; based on the target data, performing storage processing to the first database and the second database respectively, wherein the read and write speed of the first database is greater than the read and write speed of the second database; in response to the query request for the target data, when the first query state of the first database is query failure, and the second query state of the second database is the existence of the target data, the query result of the query request is determined based on the first storage time of the target data in the second database. The purpose of using different types of databases for data backup is achieved, the technical effect of improving the reliability of data in the database is achieved, and the technical problem of unsatisfactory data reliability in the database existing in the related art is solved. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0017] Figure 1 is a flowchart of an optional data query method provided according to an embodiment of the present application;

[0018] Figure 2 is a schematic diagram of an optional data query method provided according to an embodiment of the present application;

[0019] Figure 3 It is a schematic diagram of an optional data query device provided according to an embodiment of the present application. DETAILED DESCRIPTION

[0020] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0022] For the convenience of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0023] Redis (Remote Dictionary Server) is a high-performance open source key-value storage system. It uses memory as the main storage medium, so the data access speed is extremely fast, and can achieve a response time of microseconds. It also has the function of message queue, so it is suitable for scenarios that require high-speed data reading and writing, such as caching, real-time data analysis, and session management.

[0024] A relational database is a database management system designed based on a relational model. In a relational database, data is stored in the form of a two-dimensional table (i.e., a relational table). Each row in the table represents an entity, and each column represents an attribute of the entity. This structured method enables the data to have better atomicity, consistency, isolation, and persistence, and can ensure data integrity and the correct execution of transactions. It is often used to store, manage, and retrieve structured data.

[0025] A software development kit (SDK) is a collection of debugging tools, compilers, documents, and sample codes used in software development to support the development of specific platforms, services, or functions.

[0026] According to an embodiment of the present application, a method embodiment of data query is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0027] Figure 1 is a flowchart of an optional data query method provided according to an embodiment of the present application, such as Figure 1 As shown, the method comprises the following steps:

[0028] Step S102, obtaining target data;

[0029] It can be understood that the data source is determined and the target data is extracted from the data source.

[0030] Step S104, based on the target data, performing storage processing in the first database and the second database respectively, wherein the reading and writing speed of the first database is greater than the reading and writing speed of the second database;

[0031] It can be understood that the acquired target data is stored in the first database and the second database respectively, wherein the read and write speed of the first database is greater than the read and write speed of the second database, and the second database backs up the data of the first database to improve the integrity and reliability of the data. By storing the data in two databases, not only the data read and write speed can be guaranteed, so that the system maintains a high performance, but also the reliability of the data can be guaranteed, avoiding data loss problems caused by operational errors and system crashes.

[0032] Optionally, the first database can use a cache database, such as Redis, to store temporary data to speed up data access, improve the access performance of system services, and reduce the access pressure of the database. The second database can use a relational database, such as Mysql, to back up the data of the first database, enhance the integrity and reliability of the data, and ensure that when the first database crashes or its own mechanism causes data loss, data can still be obtained from the second database to ensure the continuity of system services and data security.

[0033] In an optional embodiment, based on the target data, storage processing is performed in the first database and the second database respectively, including: determining the storage time of obtaining the target data; generating storage information including the data name, data value, and storage time of the target data; and storing the storage information in the first database and the second database respectively.

[0034] It can be understood that the target data is obtained, the data name and data value of the target data are generated, the storage time of the target data is determined, and the storage information including the data name, data value and storage time is stored in the first database and the second database. The above-mentioned data name refers to the key value of the data, which indicates the storage location of the data and is used to query and locate the data. The above-mentioned data value refers to the information actually required to be stored, that is, the target data. The above-mentioned storage time refers to the current time of the system when the data is stored in the database, which is used to determine whether the data is expired. By generating the data name, the data name and the data value (that is, the target data) in the database can be matched one by one, providing a basis for subsequent data retrieval and query, and improving data query efficiency.

[0035] In an optional embodiment, after performing storage processing on the first database and the second database respectively based on the target data, the method further includes: determining a first storage result of the storage processing performed by the first database, and a second storage result of the storage processing performed by the second database; in the event that either the first storage result or the second storage result is a storage failure, performing data rollback processing on the first database and the second database respectively, wherein the data rollback processing is used to delete the storage processing based on the target data.

[0036] It can be understood that when the system receives the target data storage instruction, the system will synchronously store the target data in the first database and the second database. The two databases are tested to determine the storage results of the target data in the two databases. If the storage results of the target data in the two databases are both successful, the target data storage is completed; if the storage results of the target data in the two databases are both storage failures, or one succeeds and the other fails, data rollback processing is performed on the first database and the second database respectively. The above-mentioned data rollback processing means that when the storage fails to complete successfully, or an error occurs during the execution process, the system will delete the storage processing based on the target data and restore the storage state of the database to the state before the storage started. By introducing the data rollback processing, it is ensured that even if the storage of one database fails, the data in the two databases can maintain data consistency and integrity, providing the system with an efficient, stable and easy-to-manage data storage solution.

[0037] Optionally, rollback processing is a key action in database storage management, which is used to undo or cancel part or all operations in the data storage process to restore the database to the state before the data storage starts. Rollback processing includes starting a transaction, executing an operation, detecting an error, rolling back the operation, and completing the rollback. Starting a transaction means that when data storage starts, the database will record the initial state of the current database and generate a transaction log. Executing an operation means that the database stores the target data. Detecting an error means that if the database encounters any error during the data storage process (such as violation of database constraints, insufficient resources, operation failure, etc.), the database system will immediately stop further execution of data storage and start the rollback process. The rollback operation means that the database reads the transaction log and restores the database to the state before the data storage starts according to the transaction log. Completing the rollback means that after the database completes the rollback operation, the transaction is canceled and the database is restored to the state before the data storage starts. The rollback processing of the database is a mechanism to ensure the atomicity, consistency, isolation and persistence of the database.

[0038] In an optional embodiment, based on the target data, storage processing is performed on the first database and the second database respectively, including: determining the data name, data value, and storage information of the storage time including the target data; detecting whether the first information exists in the first database, wherein the first name included in the first information is the same as the data name, and the first value included in the first information is the same as the data value; if the first information exists in the first database, updating the first moment included in the first information to the storage moment as storage processing for the first database; updating the second moment included in the second information existing in the second database to the storage moment as storage processing for the second database, wherein the second information matches the first information.

[0039] It can be understood that when the system receives the target data storage instruction, it determines the data name, data value, and storage time of the target data, and detects whether there is first information with the same data name and data value as the target data in the first database. If such first information does not exist in the first database, the target data is stored in the first database and the second database. If such first information exists in the first database, the second information with the same data name and data value as the target data in the second database is retrieved, and the above-mentioned first information matches the second information, that is, they have the same data name, data value and storage time. The storage time of the first information in the first database is updated, and the storage time of the target data is used as the new storage time of the first information in the first database. And the storage time of the second information in the second database is updated, and the storage time of the target data is used as the new storage time of the second information in the first database. By updating the data storage time in the two databases at the same time, the consistency and integrity of the data update are ensured, and an efficient and reliable dual database data storage and update solution is provided for the system.

[0040] In an optional embodiment, the method further includes: determining a target time period in which the amount of data responded by the first database is less than a predetermined data amount threshold; in the target time period, comparing the data stored in the first database with the data stored in the second database to obtain a comparison result; when the comparison result indicates that there is a data deviation between the first database and the second database, and the operating status of the first database is normal, adjusting the data stored in the second database according to the data stored in the first database.

[0041] It can be understood that the target time period is determined to be less than the predetermined data volume threshold value for the amount of data responded by the first database (i.e., the number of data queries). The above-mentioned predetermined data volume threshold value is the maximum number of data queries that keeps the first database able to operate normally. In this target time period, the data in the first database and the second database are compared to determine whether there is a data deviation in the data in the two databases, that is, whether the data name, data value, and storage time of the same data are the same. If there is a data deviation in the data in the two databases, and the operating status of the first database is normal, the data information in the second database with deviations is adjusted based on the data information in the first database. Comparing and verifying the data in the two databases during a time period with a small amount of data queries can not only ensure that the database will not crash due to excessive data response volume, but also further improve the data consistency between the two databases, improve the data reliability of the system, and reduce the complexity and cost of database maintenance.

[0042] Step S106, in response to a query request for target data, when the first query status of the first database is query failure and the second query status of the second database is that the target data exists, determine the query result of the query request based on the first storage duration of the target data in the second database.

[0043] It can be understood that when the system receives a query request for target data, the system will first query the target data from the first database with a faster response speed. If the first query status of the first database, that is, the query result fails, the system will continue to query the target data from the second database. The reasons for the failure of the first database query include the non-existence of the target data and the crash of the first database, and the inability to perform normal queries. If the target data exists in the second database, that is, the second query status is that the target data exists, the query result of the query request is determined according to the first storage time of the target data in the second database (that is, the difference between the current time and the target data storage time). By storing the data in two databases with fast response speed and high data reliability, not only the query efficiency of the data is maintained, but also the reliability of the data and the query consistency are improved.

[0044] In an optional embodiment, based on the first storage duration of the target data in the second database, a query result of the query request is determined, including: determining the first storage duration according to the storage time indicated by the storage information and the current time; when the first storage duration is less than a predetermined duration threshold, determining the data value of the target data stored in the second database as the query result.

[0045] It can be understood that when the query of the first database fails and the target data exists in the second database, the first storage duration of the target data is determined based on the difference between the storage time and the current time in the storage information of the target data in the second database. If the first storage duration of the target data is less than the predetermined duration threshold (i.e., the validity period), it means that the target data is within the validity period, and the data value in the storage information of the target data stored in the second database is used as the query result and output; if the first storage duration of the target data is greater than the predetermined duration threshold (i.e., the validity period), it means that the target data is not within the validity period, and the query result is not output. By backing up the data of the first database in the second database, it can be ensured that the target data can still be queried when a problem occurs in the first database, which effectively solves the problem of database storage unreliability and improves the security of stored data.

[0046] Optionally, the selection of data validity period is a key decision that directly affects database performance, resource utilization, and data accuracy. The selection principles include business logic requirements, system performance and resource management, data update frequency, data importance and sensitivity, user experience, etc. Selecting and adjusting the validity period according to the above principles can effectively improve system performance, reduce resource consumption, and enhance data security and consistency.

[0047] In an optional embodiment, the second database is provided with a query switch, and the method further includes: determining application requirements of the target data; when the application requirement is that the priority of query delay is greater than the priority of data reliability, determining that the query switch is in a closed state, wherein the second database with the query switch in the closed state prohibits the execution of a data query function; when the application requirement is that the priority of data reliability is greater than the priority of query delay, determining that the query switch is in an open state, wherein the second database with the query switch in the open state allows the execution of a data query function.

[0048] It can be understood that a query switch is set in the second database, and whether the query switch is turned on is determined according to the application requirements of the target data. If the application requirements are more concerned about the query delay of the data (i.e., the data response speed) than the reliability of the data, the query switch is turned off, and the target data is only queried in the first database, and cannot be queried in the second database. If the application requirements are more concerned about the reliability of the data than the query delay of the data, the query switch is turned on, and the target data is first queried in the first database. If the query in the first database fails, the query in the second database continues. By setting the query switch, the system can dynamically adjust the data query strategy according to the priority of the application requirements, which not only guarantees the query performance, but also ensures the reliability of the data, and provides an efficient, stable and flexible data query strategy for the application system.

[0049] In an optional embodiment, the method further includes: when the first query status of the first database is a successful query, determining a second storage duration of the target data in the first database; when the second storage duration is less than a predetermined duration threshold, determining a data value of the target data stored in the first database as a query result.

[0050] It can be understood that if the first query state of the target data in the first database is a successful query, that is, the target data exists, the second storage duration of the target data in the first database is determined based on the difference between the storage time of the target data and the current time. If the second storage duration of the target data is greater than the predetermined duration threshold (i.e., the validity period), the query result is not output. If the second storage duration of the target data is less than the predetermined duration threshold (i.e., the validity period), the data value in the storage information of the target data stored in the first database is used as the query result and output. The introduction of a predetermined duration threshold can control the amount of data in the database while ensuring the freshness of the data, thereby ensuring the data query speed and the resource utilization efficiency of the database.

[0051] Through the above step S102, the target data is obtained; in step S104, based on the target data, storage processing is performed in the first database and the second database respectively, wherein the read and write speed of the first database is greater than the read and write speed of the second database; in step S106, in response to a query request for the target data, when the first query state of the first database is query failure and the second query state of the second database is the existence of the target data, the query result of the query request is determined based on the first storage time of the target data in the second database. The purpose of using different types of databases for data backup can be achieved, and the technical effect of improving the reliability of data in the database is achieved, thereby solving the technical problem of unsatisfactory data reliability in the database existing in the related art.

[0052] Based on the above embodiments and optional embodiments, the present application proposes an optional implementation method, which can not only ensure the query performance of the system, but also improve the reliability and integrity of the stored data by storing the data in two different databases. The first database of the above two different databases has good query performance, such as Redis database, and the second database can well ensure the reliability and persistence of stored data, such as Mysql database. At the same time, the query performance and data reliability of the system can be balanced by setting a query switch in the second database.

[0053] Figure 2 is a schematic diagram of an optional data query method provided according to an embodiment of the present application, such as Figure 2As shown, the first database uses a Redis database. The above-mentioned Redis database is a mature cache component used to store temporary data and speed up data access. Because of its efficient query performance, the Redis database is often used as a cache component in the software development of the industry to improve the access performance of system services and reduce the access pressure of the database. However, some businesses, such as login services, use the expiration function in the Redis database, which is not supported by mainstream traditional databases in terms of function, and the access speed is much different from that of the Redis database. Therefore, the Redis database is often used as the main storage to provide a data source for the application. The above-mentioned expiration function refers to automatically deleting or marking data that is no longer needed after a specified time as invalid. However, whether it is a separate Redis database or a Redis database cluster, the integrity and reliability of the data cannot be guaranteed. If data is lost, it will have a relatively large impact on the business, such as all logged-in users cannot access the application or access is denied, which will cause a direct system crash and terminate all businesses. Therefore, when using the Redis database, the algorithm of the relational database can be used to replace the expired query instructions in the core of the Redis database, thereby improving the data reliability of the Redis database and ensuring that the normal business is not affected when the Redis database crashes or the Redis database mechanism itself causes data loss. Figure 2 As shown, the above-mentioned relational database, i.e., the second database, adopts Mysql database. Mysql database is a mature relational database for storing data, which has atomicity, persistence, consistency, and isolation. Before storing data, Mysql database will create a table redis_t, which mainly contains the fields id (indicating the primary key), key (the key value of the data stored in the Redis database, i.e., the data name), value (the value of the data stored in the Redis database, i.e., the data value), and startTime (the current system time of the data stored in the Redis database, i.e., the storage time). startTime is usually in seconds to meet most scenarios. In scenarios with stricter time requirements, it can be in milliseconds. Figure 2 The unit is seconds.

[0054] Figure 2The upper part is a schematic diagram of the target data storage. The user issues the target data storage instruction by accessing the application APP (Application), and the Redis database and the Mysql database begin to store data. When storing data, first submit the data storage request; then start the transaction, that is, before executing the database storage operation, put the database into the transaction processing mode; then save the data A1-B1 (that is, the data name is A1, the data value is B1) to the Redis database, and set the validity period to 10 minutes (that is, the predetermined time threshold), and the time at this time is time1 (that is, the storage time); then save the data to the Mysql database, and the saved record is: (id: 1001, key: A1, value: B1, startTime: time1), which is the storage information in the database; finally, commit the transaction, indicating that the data storage has been completed. Figure 2 The username->userinfo in the column means saving data A1-B1 to the Redis database; userinfo is serialized into Json (Json, JavaScript Object Notation, a lightweight data exchange format based on JavaScript, used in various programming language environments) as the value column, which means converting the target data into Json format and storing it in the value column; return means that the previous action is completed.

[0055] Figure 2The lower part is a schematic diagram of target data query. Users issue target data query instructions by accessing the application APP, and query data in the Redis database and MySQL database. When querying data, the system first submits a query request, and the time is time2 (i.e. the current time); then query the data corresponding to the key value in the Redis database. At this time, if the Redis database crashes, or the Redis database denies service due to insufficient memory, or the target data to be queried is mistakenly deleted, resulting in a failure to query the target data in the Redis database, then continue to query the MySQL database; then the MySQL database executes the command select*from redis_t where key=A1 and startTime<(time2-10*60). Finally, the query result is returned: if the query result is obtained, it means that the target data exists in the MySQL database and has not expired; if no result is found, it means that the target data does not exist or has expired (in the MySQL database, the general processing method for non-existent and expired services is the same). The above select*from redis_t where key=A1 and startTime>(time2-10*60) means to search the redis_t table for the data value corresponding to the target data named A1 whose storage time startTime is greater than the difference between the current time (i.e. time2) and the validity period of 10 minutes (i.e. the predetermined duration threshold).

[0056] Figure 2 The core points are: use Mysql database to execute the query commands of Redis database, that is, when the Redis database cannot find the data, the Mysql database is also required to perform related query operations; use the designed specific data structure table to save data and implement commonly used Redis database commands. The table contains id, key, value, startTime, so that Mysql database or similar relational database can replace Redis database to work; a relational database replacement algorithm is given for the commonly used expiration function in Redis database.

[0057] In order to better balance data query performance and data reliability, a query switch can be set in the second database, and whether the query switch is turned on is determined based on the application requirements of the target data. If the application requirements are more concerned with data query latency (i.e., data response speed) than data reliability, the query switch is turned off, and the target data is only queried in the first database, and cannot be queried in the second database. If the application requirements are more concerned with data reliability than data query latency, the query switch is turned on, and the target data is first queried in the first database. If the query in the first database fails, the query in the second database continues. By setting the query switch, the system can dynamically adjust the data query strategy according to the priority of application requirements, which not only ensures query performance, but also ensures data reliability, providing an efficient, stable, and flexible data query strategy for the application system.

[0058] Optionally, for Figure 2 The data query process shown can be set up through the software development tool SDK. When executing the query function, it is determined whether this switch is turned on. If the switch is turned off, after the data cannot be found in the Redis database, the query function will no longer be executed in the Mysql database. This configuration has good application value for businesses that do not require high storage reliability but have high performance requirements. SDK can provide a better user experience for businesses that do not require high storage reliability but have high performance requirements, improve the value of the application of this application in actual applications, and reduce performance loss caused by increased reliability.

[0059] The above optional implementation achieves at least the following effects: by storing data in different types of databases, the efficiency of data query is guaranteed and the reliability of data is improved; by setting a query switch in the database, the data query requirements of different applications can be effectively responded to, the flexibility of data query is increased, and an efficient and reliable data query system is provided to users.

[0060] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0061] In this embodiment, a data query device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the terms "module" and "device" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.

[0062] According to an embodiment of the present application, a device embodiment for implementing a data query method is also provided. Figure 3 A schematic diagram of a data query device according to an embodiment of the present application is as follows Figure 3 As shown, the above data query device includes a target data acquisition module 302, a storage module 304, and a query module 306. The device is described below.

[0063] The target data acquisition module 302 is used to acquire target data;

[0064] The storage module 304 is connected to the target data acquisition module 302 and is used to perform storage processing in the first database and the second database respectively based on the target data, wherein the reading and writing speed of the first database is greater than the reading and writing speed of the second database;

[0065] The query module 306 is connected to the storage module 304, and is used to respond to the query request for the target data, when the first query state of the first database is query failure, and the second query state of the second database is the existence of the target data, based on the first storage duration of the target data in the second database, determine the query result of the query request. In a data query device provided by an embodiment of the present application, a target data acquisition module 302 is set to acquire the target data; a storage module 304 is connected to the target data acquisition module 302, and is used to perform storage processing to the first database and the second database respectively based on the target data, wherein the read and write speed of the first database is greater than the read and write speed of the second database; the query module 306 is connected to the storage module 304, and is used to respond to the query request for the target data, when the first query state of the first database is query failure, and the second query state of the second database is the existence of the target data, based on the first storage duration of the target data in the second database, determine the query result of the query request. The purpose of using different types of databases for data backup is achieved, and the technical effect of improving the reliability of data in the database is achieved, thereby solving the technical problem of unsatisfactory data reliability in the database existing in the related art.

[0066] It should be noted that the above modules can be implemented by software or hardware. For example, for the latter, it can be implemented in the following ways: the above modules can be located in the same processor; or the above modules can be located in different processors in any combination.

[0067] It should be noted that the target data acquisition module 302, storage module 304, and query module 306 correspond to steps S102 to S106 in the embodiment, and the examples and application scenarios implemented by the modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above embodiment. It should be noted that the modules as part of the device can be run in a computer terminal.

[0068] It should be noted that the optional or preferred implementation of this embodiment can refer to the relevant description in the embodiment, which will not be repeated here.

[0069] The above-mentioned data query device may also include a processor and a memory. The target data acquisition module 302, the storage module 304, the query module 306, etc. are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.

[0070] The processor includes a kernel, which retrieves the corresponding program unit from the memory. There can be one or more kernels. The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one storage chip.

[0071] An embodiment of the present application provides a non-volatile storage medium on which a program is stored, and when the program is executed by a processor, a data query method is implemented.

[0072] The embodiment of the present application provides an electronic device, which includes a processor, a memory, and a program stored in the memory and can be run on the processor. When the processor executes the program, the following steps are implemented: obtaining target data; based on the target data, performing storage processing to a first database and a second database respectively, wherein the read and write speed of the first database is greater than the read and write speed of the second database; in response to a query request for the target data, when the first query state of the first database is query failure and the second query state of the second database is that the target data exists, determining the query result of the query request based on the first storage duration of the target data in the second database. The device in this article can be a server, a PC, etc.

[0073] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program that is initialized with the following method steps: acquiring target data; based on the target data, performing storage processing to a first database and a second database respectively, wherein the read and write speeds of the first database are greater than the read and write speeds of the second database; in response to a query request for the target data, when a first query status of the first database is query failure and a second query status of the second database is that the target data exists, determining a query result of the query request based on a first storage duration of the target data in the second database.

[0074] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0075] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0076] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0077] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0078] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0079] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0080] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0081] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0082] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.

[0083] The above are only embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included within the scope of the claims of the present application.

Claims

1. A data query method, characterized in that: include: Get target data; Based on the target data, performing storage processing in a first database and a second database respectively, wherein a reading and writing speed of the first database is greater than a reading and writing speed of the second database; In response to a query request for the target data, when a first query status of the first database is query failure and a second query status of the second database is that the target data exists, a query result of the query request is determined based on a first storage time of the target data in the second database.

2. The method according to claim 1, characterized in that The step of performing storage processing in the first database and the second database based on the target data respectively includes: Determine a storage time for acquiring the target data; Generate storage information including the data name, data value, and storage time of the target data; The storage information is stored in the first database and the second database respectively.

3. The method according to claim 1, characterized in that The determining, based on the first storage duration of the target data in the second database, a query result of the query request includes: Determine the first storage duration according to the storage time indicated by the storage information and the current time; When the first storage duration is less than a predetermined duration threshold, a data value of the target data stored in the second database is determined as the query result.

4. The method according to claim 1, characterized in that: The second database is provided with a query switch, and the method further comprises: Determining application requirements of the target data; In the case where the priority of the application requirement is that the query delay is greater than the priority of the data reliability, determining that the query switch is in an off state, wherein the second database in which the query switch is in the off state is prohibited from executing the data query function; When the application requirement is that the priority of data reliability is greater than the priority of query latency, the query switch is determined to be in an on state, wherein the second database in which the query switch is in an on state allows execution of a data query function.

5. The method according to claim 1, characterized in that After performing storage processing in the first database and the second database respectively based on the target data, the method further includes: Determine a first storage result of the storage process performed by the first database, and a second storage result of the storage process performed by the second database; In the case that any one of the first storage result or the second storage result is a storage failure, data rollback processing is performed on the first database and the second database respectively, wherein the data rollback processing is used to delete the storage processing based on the target data.

6. The method according to claim 1, characterized in that The storing process of performing storage processing in the first database and the second database respectively based on the target data includes: Determine storage information including the data name, data value, and storage time of the target data; Detecting whether first information exists in the first database, wherein a first name included in the first information is the same as the data name, and a first value included in the first information is the same as the data value; When the first information exists in the first database, updating the first time included in the first information to the storage time as storage processing for the first database; The second time included in the second information existing in the second database is updated as the storage time, as a storage process for the second database, wherein the second information matches the first information.

7. The method according to claim 1, characterized in that The method further comprises: Determine a target time period in which the amount of data responded by the first database is less than a predetermined data amount threshold; In the target time period, the data stored in the first database is compared with the data stored in the second database to obtain a comparison result; When the comparison result indicates that there is a data deviation between the first database and the second database, and the operation status of the first database is normal, the data stored in the second database is adjusted according to the data stored in the first database.

8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: When the first query status of the first database is that the query is successful, determining a second storage time length of the target data in the first database; When the second storage duration is less than a predetermined duration threshold, a data value of the target data stored in the first database is determined as the query result.

9. A data query device, characterized in that: include: A target data acquisition module, used for acquiring target data; A storage module, used for performing storage processing in a first database and a second database respectively based on the target data, wherein the reading and writing speed of the first database is greater than the reading and writing speed of the second database; A query module is used to respond to a query request for the target data, and when a first query status of the first database is query failure and a second query status of the second database is the existence of the target data, determine a query result of the query request based on a first storage time of the target data in the second database.

10. An electronic device, characterized in that: include: One or more processors and a memory, wherein the memory is used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the data query method described in any one of claims 1 to 8.