CN111581238B - Information query method and device, electronic equipment and computer readable storage medium - Google Patents

Information query method and device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN111581238B
CN111581238B CN202010252041.5A CN202010252041A CN111581238B CN 111581238 B CN111581238 B CN 111581238B CN 202010252041 A CN202010252041 A CN 202010252041A CN 111581238 B CN111581238 B CN 111581238B
Authority
CN
China
Prior art keywords
information
database
time length
target
time
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010252041.5A
Other languages
Chinese (zh)
Other versions
CN111581238A (en
Inventor
周志远
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing QIYI Century Science and Technology Co Ltd
Original Assignee
Beijing QIYI Century Science and Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing QIYI Century Science and Technology Co Ltd filed Critical Beijing QIYI Century Science and Technology Co Ltd
Priority to CN202010252041.5A priority Critical patent/CN111581238B/en
Publication of CN111581238A publication Critical patent/CN111581238A/en
Application granted granted Critical
Publication of CN111581238B publication Critical patent/CN111581238B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Abstract

The embodiment of the invention provides an information query method and device, electronic equipment and a computer-readable storage medium, and belongs to the technical field of information query. The information query method comprises the following steps: receiving a query request message of state information; acquiring a first time length, a second time length and a third time length according to the query request message; and determining a target database according to the comparison result of the first time length with the second time length and the third time length respectively, and inquiring state information in the target database. The technical scheme provided by the embodiment of the invention can solve the problem of inaccurate information query results caused by delay in synchronization between the master database and the slave database in the prior art to a certain extent.

Description

Information query method and device, electronic equipment and computer readable storage medium
Technical Field
The present invention relates to the field of information query technologies, and in particular, to an information query method and apparatus, an electronic device, and a computer readable storage medium.
Background
Currently, service authorization is increasingly popular by scanning bar codes (such as one-dimensional bar codes, two-dimensional bar codes and the like), for example, code scanning login, code scanning payment, code scanning focusing on public numbers, code scanning and friend adding and the like.
In the prior art, in order to improve service availability and service performance, corresponding servers are usually deployed in different regions for one code scanning authorization service. Whereas the data is stored in a master-slave mode, i.e.: a piece of data is stored in a master database and at least one slave database corresponding to the master database. The master database is mainly used for writing and updating data, and the slave database is mainly used for inquiring data. After the master database writes or updates data, data synchronization with the slave database is required.
However, due to the delay in data synchronization between the master database and the slave database, when the slave database queries data, the latest data may not be queried, thereby resulting in inaccurate data query results. For example, the terminal device requests the server to generate the two-dimensional code, and the server generates the two-dimensional code according to the request and stores the two-dimensional code information in the main database. After receiving and displaying the two-dimension code sent by the server, the terminal equipment inquires the state information of the two-dimension code from the server, and at the moment, the server is likely to not inquire the information of the two-dimension code in the slave database because the data synchronization between the master database and the slave database is not completed, so that the two-dimension code is considered invalid, and the accuracy of an inquiry result is influenced.
Disclosure of Invention
The invention provides an information query method and device, electronic equipment and a computer readable storage medium, so as to solve the problem that in the prior art, the information query result is inaccurate due to delay in synchronization between a master database and a slave database to a certain extent.
In a first aspect of the present invention, an information query method is provided, applied to a server, where the information query method includes:
receiving a query request message of state information; wherein the status information includes: at least one of state information of a target bar code and state information of a service corresponding to the target bar code;
acquiring a first time length, a second time length and a third time length according to the query request message; wherein, the first duration is: the duration between the creation time of the target bar code and the receiving time of the query request message, and the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: a duration between the creation time of the target barcode and the scanned time of the target barcode;
determining a target database according to comparison results of the first time length, the second time length and the third time length respectively, and inquiring the state information in the target database; wherein the target database is the master database or the slave database.
Optionally, the determining the target database according to the comparison result of the first time length with the second time length and the third time length respectively includes:
determining the target database as the main database under the condition that the comparison result is that the first time length is smaller than the second time length;
determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length;
and determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length.
Optionally, after the receiving the query request message of the status information, the information query method further includes:
in the event that a failure in data synchronization between the master database and the slave database is detected, determining to query the master database for the status information.
Optionally, the query request message includes: token information corresponding to the target bar code, the token information comprising: time field information, storage location field information, and service type field information are created.
Optionally, acquiring the first duration, the second duration, and the third duration according to the query request message includes:
acquiring the token information in the query request message;
determining the first duration according to the creation time field information in the token information;
determining the second duration according to the storage location field information in the token information;
and determining the third duration according to the service type field information in the token information.
Optionally, before the receiving the query request message of the state information, the information query method further includes:
acquiring target information; wherein the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code;
and storing the acquired target information in a main database closest to the server.
In a second aspect of the present invention, there is provided an information query apparatus applied to a server, the information query apparatus including:
the receiving module is used for receiving the inquiry request message of the state information; wherein the status information includes: at least one of state information of a target bar code and state information of a service corresponding to the target bar code;
The acquisition module is used for acquiring the first time length, the second time length and the third time length according to the query request message; wherein, the first duration is: the duration between the creation time of the target bar code and the receiving time of the query request message, and the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: a duration between the creation time of the target barcode and the scanned time of the target barcode;
the first determining module is used for determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, and inquiring the state information in the target database; wherein the target database is the master database or the slave database.
Optionally, the first determining module includes:
the first determining unit is used for determining that the target database is the main database when the comparison result is that the first duration is smaller than the second duration; determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length; and determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length.
Optionally, the information query apparatus further includes:
and the second determining module is used for determining to query the state information in the master database under the condition that the data synchronization between the master database and the slave database is detected to be faulty.
Optionally, the query request message includes: token information corresponding to the target bar code, the token information comprising: time field information, storage location field information, and service type field information are created.
Optionally, the acquiring module includes:
an obtaining unit, configured to obtain the token information in the query request message;
a second determining unit, configured to determine the first duration according to creation time field information in the token information; determining the second duration according to the storage location field information in the token information; and determining the third duration according to the service type field information in the token information.
Optionally, the information query apparatus further includes:
the acquisition module is used for acquiring target information; wherein the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code;
And the storage module is used for storing the acquired target information in a main database closest to the server.
In a third aspect of the present invention, there is also provided an electronic device, including a processor, a communication interface, a memory, and a communication bus, where the processor, the communication interface, and the memory complete communication with each other through the communication bus;
a memory for storing a computer program;
and the processor is used for realizing the steps in the video playing method or the steps in the information inquiring method when executing the program stored in the memory.
In a fourth aspect of the present invention, there is also provided a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the information query method as described above.
In a fifth aspect of embodiments of the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform the information query method as described above.
Aiming at the prior art, the invention has the following advantages:
in the embodiment of the invention, when the state information is inquired, the target database for inquiring the state information is determined by combining the time length (namely the first time length) between the creation time of the bar code and the receiving time of the inquiry request message, the data synchronization delay time length (namely the second time length) of the master database and the corresponding slave database and the time length (namely the third time length) between the creation time of the target bar code and the scanned time of the target bar code. Because the three time periods are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three time periods, the state information can be estimated in which database can be inquired, so that the target database for inquiring the state information is determined, the state information can be timely and accurately fed back, the influence of the synchronization delay of the master database and the slave database on the state information inquiry is reduced, and the delay of the state information change visible to a user is reduced.
The foregoing description is only an overview of the present invention, and is intended to be implemented in accordance with the teachings of the present invention in order that the same may be more clearly understood and to make the same and other objects, features and advantages of the present invention more readily apparent.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments will be briefly described below.
Fig. 1 is a schematic flow chart of an information query method according to an embodiment of the present invention;
fig. 2 is a flow chart of another information query method according to an embodiment of the present invention;
FIG. 3 is a schematic diagram of a relationship between a master database and a slave database according to an embodiment of the present invention;
fig. 4 is a block diagram of an information query apparatus according to an embodiment of the present invention;
FIG. 5 is a block diagram of another information query apparatus according to an embodiment of the present invention;
fig. 6 is a block diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the invention to those skilled in the art.
Fig. 1 is a flow chart of an information query method according to an embodiment of the present invention. The information query method is applied to the server.
As shown in fig. 1, the information query method may include:
step 101: a query request message for status information is received.
The query request message in this step is used for requesting query status information, where the status information includes: at least one of status information of the target bar code and status information of a service corresponding to the target bar code. The target bar code may be a one-dimensional bar code (i.e., bar code), a two-dimensional bar code (i.e., two-dimensional bar code), or a bar code of more dimensions. Status information of the target barcode may include, but is not limited to: a to-be-scanned state, a failure state, etc. The status information of the service corresponding to the target barcode may include, but is not limited to: authorization success status (e.g., payment success, login success), authorization failure status (e.g., payment failure, login failure), etc.
In the embodiment of the invention, the server can receive the query requests of other electronic equipment for the state information of the target bar code and/or the state information of the service corresponding to the target bar code, for example, the query requests of the state information of the target bar code only, the query requests of the state information of the service corresponding to the target bar code only, or the query requests of the state information of the target bar code and the state information of the service corresponding to the target bar code. The other electronic devices described herein may be terminal devices, or may be other servers.
Step 102: and acquiring the first time length, the second time length and the third time length according to the received query request message.
Wherein, the first duration is: the length of time between the creation time of the target barcode and the receipt time of the query request message. The second time period is as follows: the master database storing the status information and the corresponding slave database are synchronized for a delay time. The third time period is as follows: the length of time between the creation time of the target barcode and the scanned time of the target barcode. The state information of the target bar code and the state information of the business corresponding to the target bar code are stored in the same main database. Typically, the second time period is less than the third time period.
In the embodiment of the invention, after receiving the query request message, the server can acquire the first duration, the second duration and the third duration, so as to be used for determining the target database of the query state information later.
In the embodiment of the present invention, the second duration may be preset. The value of the second time period can also be adjusted according to real-time monitoring of the data synchronization time of the master database and the slave database.
In the embodiment of the invention, the third time length can be set according to the experience time of the user for completing scanning the target bar code. The value of the third duration can also be adjusted according to the actual time obtained by statistics and used for completing scanning of the target bar code for the user. The scanned time of the target bar code refers to the time when the target bar code is scanned.
Step 103: and determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, and inquiring state information in the target database.
In the embodiment of the invention, after the first time length, the second time length and the third time length are acquired, the first time length is compared with the second time length and the third time length respectively, then a target database for inquiring the state information is determined according to the comparison result, then the required state information is inquired in the target database, and the inquired state information is sent to target electronic equipment. The target electronic device is the electronic device that sent the query request message.
The target database is a master database storing state information or a slave database corresponding to the master database. When the number of the corresponding slave databases is at least two, the slave databases are selected according to the positions in the ground.
In the embodiment of the invention, when the state information is inquired, the target database for inquiring the state information is determined by combining the time length (namely the first time length) between the creation time of the bar code and the receiving time of the inquiry request message, the data synchronization delay time length (namely the second time length) of the master database and the corresponding slave database and the time length (namely the third time length) between the creation time of the target bar code and the scanned time of the target bar code. Because the three durations are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three durations, it can be determined which database stores the state information, i.e. in which database the state information can be queried, and further the target database used for querying the state information can be determined, for example, when determining that the master database and the slave database both store the state information to be queried (i.e. the master-slave is completed with data synchronization), the slave database can be selected to query the state information, thereby reducing the pressure of the master database while ensuring the query performance. When determining that only the state information to be queried is stored in the main database (namely, the synchronization of the master database and the slave database is not completed), querying the state information in the main database so as to timely feed back the accurate state information, reducing the influence of the synchronization delay of the master database and the slave database on the state information query, and reducing the delay of the state information change to the visibility of a user.
Fig. 2 is a flow chart of another information query method according to an embodiment of the present invention. The information query method is applied to the server.
As shown in fig. 2, the information query method may include:
step 201: a query request message for status information is received.
For an explanation of this step, reference is made to the foregoing detailed description of step 101, and no further description is given here.
Step 202: and obtaining token information corresponding to the target bar code in the query request message.
The query request message includes: token information corresponding to the target bar code. The token information is composed of at least two field information including: time field information, storage location field information, and service type field information are created.
In the embodiment of the invention, after receiving the inquiry request message, the token information corresponding to the target bar code is acquired from the inquiry request message.
Step 203: determining the first duration according to creation time field information in the token information; determining a second time length according to the storage position field information in the token information; and determining a third duration according to the service type field information in the token information.
For the explanation of the first duration, the second duration, and the third duration, reference may be made to the detailed descriptions of these three durations in step 102, which are not repeated here.
In the embodiment of the invention, the server can determine the information required by the query strategy of the state information according to the field information in the token information, thereby flexibly executing the query strategy.
For example, the creation time of the target barcode may be acquired from the creation time field information in the token information. The first time period may then be determined based on the creation time and the time of receipt of the query request message.
For another example, the main database storing the status information and the machine room in which the main database is located may be determined based on the storage location field information in the token information. After determining the master database, a slave database corresponding to the master database may be determined. After determining the master database and the corresponding slave database, the data synchronization delay duration (i.e., the second duration) corresponding to the master database and the corresponding slave database may be determined.
For another example, according to the service type field information in the token information, the service type corresponding to the target bar code can be determined. A third time period corresponding to the traffic type may then be determined.
Step 204: and determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, and inquiring state information in the target database.
For an explanation of this step, reference is made to the foregoing detailed description of step 103, and no further description is given here.
In the embodiment of the invention, when the state information is inquired, the target database for inquiring the state information is determined by combining the time length (namely the first time length) between the creation time of the bar code and the receiving time of the inquiry request message, the data synchronization delay time length (namely the second time length) of the master database and the corresponding slave database and the time length (namely the third time length) between the creation time of the target bar code and the scanned time of the target bar code. Because the three time lengths are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three time lengths, the database in which the state information is stored can be determined, and the target database for inquiring the state information can be further determined. For example, when it is determined that the state information can be queried in both the master database and the slave database (i.e., the master-slave completes data synchronization), the state information can be queried in the slave database, so that the master database pressure can be reduced while the query performance is ensured. When state information can only be inquired in the main database (namely, the synchronization of the master database and the slave database is not completed), the state information is inquired in the main database so as to feed back accurate state information in time, the influence of the synchronization delay of the master database and the slave database on the state information inquiry is reduced, and the delay of the state information change to the user is reduced.
Optionally, step 204: according to the comparison result of the first time length with the second time length and the third time length respectively, determining the target database of the query state information can comprise:
under the condition that the comparison result is that the first time length is smaller than the second time length, determining the target database as a main database; determining the target database as a slave database under the condition that the comparison result is that the first time length is longer than or equal to the second time length and the first time length is shorter than the third time length; and under the condition that the comparison result is that the first time length is greater than or equal to the third time length, determining the target database as a main database.
Under the condition that the first time length is smaller than the second time length, the target bar code is considered to be in an initial state (namely a state of waiting to scan), and data synchronization is not completed between the master database and the slave database, only state information to be queried is stored in the master database, and if the state information is queried in the slave database, a created record of the target bar code can not be queried, so that under the condition, the state information can be queried directly from the master database, accurate state information can be fed back to a user in time, the influence of synchronization delay of the master database and the slave database on the state information query is reduced, and the accuracy of a query result is improved.
Under the condition that the first time length is longer than or equal to the second time length and the first time length is shorter than the third time length, the target bar code is considered to be in an initial state, and data synchronization is completed between the master database and the slave database, it can be determined that state information to be queried is stored in both the master database and the slave database, namely: the required state information can be queried in both the master database and the slave database, so in this case, the state information can be queried in the slave database to reduce the pressure of the master database while ensuring the query performance.
Under the condition that the first time length is longer than or equal to the third time length, the target bar code is considered to be in a scanned code state, at the moment, whether the scanned code state of the target bar code is synchronous between the master database and the slave database or not can be judged, in order to feed back required state information to the target electronic equipment as soon as possible, delay of state information change visible to a user is reduced, the required state information can be inquired in the master database, and timeliness of information acquisition of the user is guaranteed.
Optionally, after the first time period is longer than the validity period of the target bar code, the server directly feeds back the information that the target bar code has failed to the target electronic device. The expiration date of the target bar code can be set according to the service type corresponding to the target bar code.
Optionally, in the case that a failure of data synchronization between the master database and the slave database is detected, querying state information in the master database is determined to ensure querying performance.
Optionally, the token information further comprises query index field information. By querying the index field information, the storage position of the state information in the main database can be found in the main database.
Optionally, before step 201, the information query method further includes: and acquiring target information, and storing the acquired target information in a main database closest to the server.
Wherein, the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code.
In the embodiment of the invention, when the target bar code is generated, the server can acquire and store the coding information of the target bar code, the initial state information (such as the state of the code to be scanned) of the target bar code and the initial state information (such as the unauthorized state) of the service corresponding to the target bar code. After the target bar code is generated, if the state of the target bar code or the state of the service corresponding to the target bar code is changed, the server can acquire new state information and enable the new state information to replace the previous state information, so that the state information is updated.
In the embodiment of the invention, the nearby principle is adopted for storing the target information, namely the server stores the acquired target information in the main database closest to the server, so that the information storage time can be shortened, and the information storage efficiency can be improved.
When the main database is arranged in the server, the target information is stored in the main database in the server. When the main database is not arranged in the server, other servers closest to the server are searched, when the main database is arranged in the other servers, the target information is stored in the main database in the other servers, and the position information of the main database is recorded so as to search the main database.
In order to better understand the information query method provided by the embodiment of the present invention, an example is described below.
In this example, it is assumed that the target barcode is a two-dimensional code. The entity device to which this example relates includes: the device comprises a scanned code terminal, a code scanning terminal and a server. The scanned code terminal is used for displaying the two-dimensional code waiting to be scanned. The code scanning terminal is used for scanning the two-dimensional code displayed by the code scanning terminal. The server supports and manages the code scanning authorization service corresponding to the two-dimensional code.
Code scanning flow description:
1. the scanned code terminal requests the server to generate the two-dimensional code.
2. The server creates and stores a token (hereinafter referred to as token) corresponding to the two-dimensional code according to the request of the scanned code terminal, and returns the token to the scanned code terminal.
The server creates the token and writes the token in the main database in close geographic locations. Typically, the server is written in a master database in a machine room where the server is located (hereinafter referred to as the present machine room). The master database may be a master database provided in the server. When the main database is not set in the server, the main database is the main database set in other servers in the machine room.
In general, in order to improve service availability and service performance, a service is deployed in a machine room in different areas. One or more servers are arranged in each machine room, and service business is supported and realized by the servers. Each machine room is provided with a master database, and each master database is provided with slave databases in the machine room or other machine rooms where the master databases are located. For example, taking the master database 2 in fig. 3 as an example, the slave database 2 corresponding to the master database 2 is disposed in the machine room b in which the master database 2 is located, and the slave databases 2 corresponding to the master database 2 are also disposed in the machine rooms a and c. The slave database 1 in the figure is a slave database corresponding to the master database 1, the slave database 2 in the figure is a slave database corresponding to the master database 2, and the slave database 3 in the figure is a slave database corresponding to the master database 3.
Wherein the storing of the token is indexed by the token. In addition, the token contains the index of the current two-dimension code data record and also encodes the information such as the number, the creation time, the service type and the like of the main database. For the token, since the encoded contents can use a fixed-length numerical type, the length of the token can also be fixed-length.
3. The scanned code terminal codes the received token into a two-dimensional code for display, and the server is inquired about the state of the two-dimensional code at intervals of preset time.
4. The code scanning terminal scans the two-dimensional code to obtain the token, and sends the obtained token to the server for service authorization.
5. The server determines whether to carry out service authorization according to the token sent by the code scanning terminal, updates the state of the token according to the determination result, and stores service authorization data when agreeing to service authorization; or storing refusal authorization data when refusing service authorization.
6. The scanned code terminal continuously inquires the state of the two-dimensional code and the service authorization state of the server every preset time, and displays the inquired result.
The query result may be "authorization success", "authorization failure", or "two-dimensional code has been invalidated", etc.
When the code scanning terminal requests the server to update the two-dimensional code state or the service authorization state, the server analyzes the token in the request to obtain the main database information for storing the token, and the corresponding token state update is performed in the main database.
Information inquiry strategy:
when the terminal equipment (such as a scanned code terminal and a scanned code terminal) inquires the two-dimension code state and/or the service authorization state from the server, the transmitted inquiry request comprises a token obtained according to the two-dimension code. The server parses the relevant creation information from the token. For example, token=symmetric encryption (dbIndex, businessType, timestamp), where the token index is an index of a two-dimensional code data record. The database in which the token is stored and the machine room in which the master database in which the token is stored can be known from dbIndex. The creation time of the token can be known from the timestamp. The service type corresponding to the token (namely, the service type corresponding to the two-dimension code) can be obtained according to the businessType, and the validity period of the two-dimension code can be obtained according to the service type.
Because the token is encrypted, if the decryption of the server fails, the query request is considered to be an illegal request, and the denial can be directly carried out. If the server decrypts successfully, the server can execute the following query strategy according to the information obtained by analyzing the token:
1. If the time for creating the two-dimension code is smaller than the data synchronization delay time of the master database and the corresponding slave database, the information is directly searched from the master database, so that the problem that the record is not just created in the process of searching from the slave database is avoided.
2. If the time for creating the two-dimension code is greater than or equal to the data synchronization delay time of the master database and the corresponding slave database and less than the experience time for identifying the code scanning (namely, the time from the time for creating the two-dimension code to the time when the two-dimension code is scanned), the information is searched in the slave database, and the searching performance is ensured to the greatest extent.
Wherein, when determining to query information from the database, the slave database is selected by adopting a proximity principle. If the slave database corresponding to the master database is arranged in the machine room, the information is queried in the slave database of the machine room. If the slave databases corresponding to the master database are not arranged in the machine room, other corresponding slave databases are found nearby, and information is queried in the slave databases.
For example, as shown in fig. 3, a master database storing a token is a master database 2, and if a slave database 2 corresponding to the master database 2 is provided in a machine room b where the master database 2 is located, it is determined that information is queried in the slave database 2. If the master database storing the token is the master database 3, the slave database 3 corresponding to the master database 3 is not provided in the machine room c in which the master database 3 is located, and the slave databases 3 corresponding to the master database 3 are provided in the machine rooms a and b, the machine room closest to the machine room c is determined in the machine rooms a and b, and if the machine room closest to the machine room c is the machine room b, the information is searched in the slave database 3 in the machine room b.
3. If the time for creating the two-dimension code is longer than or equal to the experience time for scanning the code confirmation, the information is searched in the main database, so that the service authorization state can be shown to the user as soon as possible.
4. If the time for creating the two-dimension code is longer than the receiving time of the query request, the server directly returns the invalid information of the two-dimension code.
5. If the data synchronization between the master database and the slave database is detected to be faulty, the slave database cannot synchronize the data with the master database for a long time, so that the server can configure all queries to be performed through the master database to ensure service availability.
In the embodiment of the invention, when the state information is queried, the target database for querying the state information is determined by combining the first time length, the second time length and the third time length. Because the three time lengths are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three time lengths, the state information can be estimated in which database can be inquired, so that the target database for inquiring the information is determined, the accurate state information can be fed back in time, and the influence of the synchronization delay of the master database and the slave database on the information inquiry is reduced.
Fig. 4 is a block diagram of an information query apparatus according to an embodiment of the present invention, where the information query apparatus is applied to a server.
As shown in fig. 4, the information query apparatus 400 may include:
the receiving module 401 is configured to receive a query request message of status information.
Wherein the status information includes: at least one of the state information of the target bar code and the state information of the business corresponding to the target bar code.
The obtaining module 402 is configured to obtain a first duration, a second duration, and a third duration according to the query request message.
Wherein, the first duration is: the duration between the creation time of the target bar code and the receiving time of the query request message, and the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: and the time length between the creation time of the target bar code and the scanned time of the target bar code.
A first determining module 403, configured to determine a target database according to the comparison result of the first time length with the second time length and the third time length, and query the state information in the target database.
Wherein the target database is the master database or the slave database.
In the embodiment of the invention, when the state information is inquired, the target database for inquiring the state information is determined by combining the time length (namely the first time length) between the creation time of the bar code and the receiving time of the inquiry request message, the data synchronization delay time length (namely the second time length) of the master database and the corresponding slave database and the time length (namely the third time length) between the creation time of the target bar code and the scanned time of the target bar code. Because the three time periods are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three time periods, the state information can be estimated in which database can be inquired, so that the target database for inquiring the state information is determined, the state information can be timely and accurately fed back, the influence of the synchronization delay of the master database and the slave database on the state information inquiry is reduced, and the delay of the state information change visible to a user is reduced.
Fig. 5 is a block diagram of another information query apparatus according to an embodiment of the present invention, which is applied to a server.
As shown in fig. 5, the information query apparatus 500 may include:
the receiving module 501 is configured to receive a query request message of status information.
Wherein the status information includes: at least one of the state information of the target bar code and the state information of the business corresponding to the target bar code.
The obtaining module 502 is configured to obtain a first duration, a second duration, and a third duration according to the query request message.
Wherein, the first duration is: the duration between the creation time of the target bar code and the receiving time of the query request message, and the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: and the time length between the creation time of the target bar code and the scanned time of the target bar code.
A first determining module 503, configured to determine a target database according to the comparison results of the first time period with the second time period and the third time period, and query the state information in the target database.
Wherein the target database is the master database or the slave database.
Optionally, the first determining module 503 includes:
A first determining unit 5031, configured to determine that the target database is the master database if the comparison result indicates that the first duration is less than the second duration; determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length; and determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length.
Optionally, the information query apparatus 500 further includes:
a second determining module 504, configured to determine to query the master database for the status information if a failure of data synchronization between the master database and the slave database is detected.
Optionally, the query request message includes: token information corresponding to the target bar code, the token information comprising: time field information, storage location field information, and service type field information are created.
Optionally, the obtaining module 502 includes:
an obtaining unit 5021, configured to obtain the token information in the query request message.
A second determining unit 5022, configured to determine the first duration according to creation time field information in the token information; determining the second duration according to the storage location field information in the token information; and determining the third duration according to the service type field information in the token information.
Optionally, the information query apparatus further includes:
an acquisition module 505, configured to acquire target information.
Wherein the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code.
And a storage module 506, configured to store the obtained target information in a main database closest to the server.
In the embodiment of the invention, when the state information is inquired, the target database for inquiring the state information is determined by combining the time length (namely the first time length) between the creation time of the bar code and the receiving time of the inquiry request message, the data synchronization delay time length (namely the second time length) of the master database and the corresponding slave database and the time length (namely the third time length) between the creation time of the target bar code and the scanned time of the target bar code. Because the three time periods are directly related to the state of the target bar code, the state of the service corresponding to the target bar code and the data synchronization between the master database and the slave database, by comparing the three time periods, the state information can be estimated in which database can be inquired, so that the target database for inquiring the state information is determined, the state information can be timely and accurately fed back, the influence of the synchronization delay of the master database and the slave database on the state information inquiry is reduced, and the delay of the state information change visible to a user is reduced.
For the device embodiments described above, reference is made to the description of the method embodiments for the relevant points, since they are substantially similar to the method embodiments.
The embodiment of the invention also provides electronic equipment which can be a server. As shown in fig. 6, the device comprises a processor 601, a communication interface 602, a memory 603 and a communication bus 604, wherein the processor 601, the communication interface 602 and the memory 603 perform communication with each other through the communication bus 604.
Memory 603 for storing a computer program.
When the electronic device is a terminal device, the processor 601 is configured to execute the program stored in the memory 603, and implement the following steps:
receiving a query request message of state information; acquiring a first time length, a second time length and a third time length according to the query request message; and determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, and inquiring the state information in the target database.
Wherein the status information includes: at least one of state information of a target bar code and state information of a service corresponding to the target bar code; the first duration is as follows: the duration between the creation time of the target bar code and the receiving time of the query request message, and the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: a duration between the creation time of the target barcode and the scanned time of the target barcode; the target database is the master database or the slave database.
Optionally, the determining the target database according to the comparison result of the first time length with the second time length and the third time length respectively includes:
determining the target database as the main database under the condition that the comparison result is that the first time length is smaller than the second time length;
determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length;
and determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length.
Optionally, after the receiving the query request message of the status information, when the processor 601 executes the program stored on the memory 603, the following steps are further implemented:
in the event that a failure in data synchronization between the master database and the slave database is detected, determining to query the master database for the status information.
Optionally, the obtaining the first duration, the second duration, and the third duration according to the query request message includes:
Acquiring the token information in the query request message;
determining the first duration according to the creation time field information in the token information;
determining the second duration according to the storage location field information in the token information;
and determining the third duration according to the service type field information in the token information.
Optionally, before the receiving the query request message of the status information, the processor 601 executes the program stored on the memory 603, and further performs the following steps:
acquiring target information; and storing the acquired target information in a main database closest to the server.
Wherein the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code.
The communication bus mentioned by the above electronic device may be a peripheral component interconnect standard (Peripheral Component Interconnect, abbreviated as PCI) bus or an extended industry standard architecture (Extended Industry Standard Architecture, abbreviated as EISA) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, the figures are shown with only one bold line, but not with only one bus or one type of bus.
The communication interface is used for communication between the terminal and other devices.
The memory may include random access memory (Random Access Memory, RAM) or non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
The processor may be a general-purpose processor, including a central processing unit (Central Processing Unit, CPU for short), a network processor (Network Processor, NP for short), etc.; but also digital signal processors (Digital Signal Processing, DSP for short), application specific integrated circuits (Application Specific Integrated Circuit, ASIC for short), field-programmable gate arrays (Field-Programmable Gate Array, FPGA for short) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
In yet another embodiment of the present invention, a computer readable storage medium is provided, in which instructions are stored, which when executed on a computer, cause the computer to perform the information query method described in the above embodiment.
In yet another embodiment of the present invention, a computer program product containing instructions that, when run on a computer, cause the computer to perform the information query method described in the above embodiment is also provided.
In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented in software, may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When loaded and executed on a computer, produces a flow or function in accordance with embodiments of the present invention, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a computer network, or other programmable apparatus. The computer instructions may be stored in or transmitted from one computer-readable storage medium to another, for example, by wired (e.g., coaxial cable, optical fiber, digital Subscriber Line (DSL)), or wireless (e.g., infrared, wireless, microwave, etc.). The computer readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. that contains an integration of one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), etc.
It is noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
In this specification, each embodiment is described in a related manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is only of the preferred embodiments of the present invention and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (10)

1. An information query method applied to a server is characterized by comprising the following steps:
receiving a query request message of state information; wherein the status information includes: at least one of state information of a target bar code and state information of a service corresponding to the target bar code;
acquiring a first time length, a second time length and a third time length according to the query request message; wherein, the first duration is: a duration between the creation time of the target barcode and the reception time of the query request message; the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: a duration between the creation time of the target barcode and the scanned time of the target barcode; the creation time of the target bar code is the time of the server to create a token corresponding to the target bar code;
Determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, wherein the method comprises the following steps: determining the target database as the main database under the condition that the comparison result is that the first time length is smaller than the second time length; determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length; determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length;
querying the target database for the state information; wherein the target database is the master database or the slave database.
2. The information query method as claimed in claim 1, wherein after said receiving a query request message of status information, the information query method further comprises:
in the event that a failure in data synchronization between the master database and the slave database is detected, determining to query the master database for the status information.
3. The information query method as claimed in claim 1, wherein the query request message includes: token information corresponding to the target bar code, the token information comprising: time field information, storage location field information, and service type field information are created.
4. The information query method according to claim 3, wherein the obtaining the first duration, the second duration, and the third duration according to the query request message includes:
acquiring the token information in the query request message;
determining the first duration according to the creation time field information in the token information;
determining the second duration according to the storage location field information in the token information;
and determining the third duration according to the service type field information in the token information.
5. The information query method as claimed in claim 1, wherein prior to said receiving the query request message of the status information, the information query method further comprises:
acquiring target information; wherein the target information includes: target bar code information, state information of the target bar code and state information of a service corresponding to the target bar code;
And storing the acquired target information in a main database closest to the server.
6. An information query apparatus applied to a server, the information query apparatus comprising:
the receiving module is used for receiving the inquiry request message of the state information; wherein the status information includes: at least one of state information of a target bar code and state information of a service corresponding to the target bar code;
the acquisition module is used for acquiring the first time length, the second time length and the third time length according to the query request message; wherein, the first duration is: a duration between the creation time of the target barcode and the reception time of the query request message; the second duration is: the master database storing the state information and the corresponding slave database synchronize the delay time length; the third duration is as follows: a duration between the creation time of the target barcode and the scanned time of the target barcode; the creation time of the target bar code is the time of the server to create a token corresponding to the target bar code;
the first determining module is used for determining a target database according to the comparison results of the first time length, the second time length and the third time length respectively, and inquiring the state information in the target database; wherein the target database is the master database or the slave database;
The first determining module comprises a first determining unit, wherein the first determining unit is used for determining that the target database is the main database when the comparison result is that the first duration is smaller than the second duration; determining the target database as the slave database when the comparison result is that the first time length is greater than or equal to the second time length and the first time length is less than the third time length; and determining the target database as the main database under the condition that the comparison result is that the first time length is greater than or equal to the third time length.
7. The information query apparatus of claim 6, wherein the query request message comprises: token information corresponding to the target bar code, the token information comprising: time field information, storage location field information, and service type field information are created.
8. The information query apparatus of claim 7, wherein the acquisition module comprises:
an obtaining unit, configured to obtain the token information in the query request message;
a second determining unit, configured to determine the first duration according to creation time field information in the token information; determining the second duration according to the storage location field information in the token information; and determining the third duration according to the service type field information in the token information.
9. An electronic device, comprising: a processor, a communication interface, a memory, and a communication bus; the processor, the communication interface and the memory complete communication with each other through a communication bus;
a memory for storing a computer program;
a processor for implementing the steps of the information inquiry method according to any one of claims 1 to 5 when executing a program stored on a memory.
10. A computer-readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the information query method of any one of claims 1 to 5.
CN202010252041.5A 2020-04-01 2020-04-01 Information query method and device, electronic equipment and computer readable storage medium Active CN111581238B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010252041.5A CN111581238B (en) 2020-04-01 2020-04-01 Information query method and device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010252041.5A CN111581238B (en) 2020-04-01 2020-04-01 Information query method and device, electronic equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN111581238A CN111581238A (en) 2020-08-25
CN111581238B true CN111581238B (en) 2023-10-24

Family

ID=72112969

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010252041.5A Active CN111581238B (en) 2020-04-01 2020-04-01 Information query method and device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN111581238B (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113076343B (en) * 2021-04-30 2024-04-05 北京京东振世信息技术有限公司 Data query method, device, equipment and storage medium

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016091069A1 (en) * 2014-12-12 2016-06-16 北京奇虎科技有限公司 Data operation method and device
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN107766575A (en) * 2017-11-14 2018-03-06 中国联合网络通信集团有限公司 The data bank access method and device of read and write abruption
CN108304406A (en) * 2017-01-12 2018-07-20 阿里巴巴集团控股有限公司 A kind of data base read-write method, apparatus and electronic equipment
CN109189851A (en) * 2018-06-29 2019-01-11 网宿科技股份有限公司 Data access method, database facility and master-slave database instance system
CN110334150A (en) * 2019-06-05 2019-10-15 上海易点时空网络有限公司 Monitor method, monitor terminal and the system of master-slave database synchronizing relay
CN110362625A (en) * 2019-05-30 2019-10-22 杭州数梦工场科技有限公司 Data base read-write separation method, device, electronic equipment and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2016091069A1 (en) * 2014-12-12 2016-06-16 北京奇虎科技有限公司 Data operation method and device
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN108304406A (en) * 2017-01-12 2018-07-20 阿里巴巴集团控股有限公司 A kind of data base read-write method, apparatus and electronic equipment
CN107766575A (en) * 2017-11-14 2018-03-06 中国联合网络通信集团有限公司 The data bank access method and device of read and write abruption
CN109189851A (en) * 2018-06-29 2019-01-11 网宿科技股份有限公司 Data access method, database facility and master-slave database instance system
CN110362625A (en) * 2019-05-30 2019-10-22 杭州数梦工场科技有限公司 Data base read-write separation method, device, electronic equipment and storage medium
CN110334150A (en) * 2019-06-05 2019-10-15 上海易点时空网络有限公司 Monitor method, monitor terminal and the system of master-slave database synchronizing relay

Also Published As

Publication number Publication date
CN111581238A (en) 2020-08-25

Similar Documents

Publication Publication Date Title
CN102713865B (en) Authorization data cache management
AU2016382908A1 (en) Short link processing method, device and server
CN111475519B (en) Data caching method and device
WO2019100853A1 (en) Page query method, device, and electronic apparatus
CN106066894A (en) Data global buffer method and data global buffer device
CN109254981B (en) Data management method and device of distributed cache system
CN111221469A (en) Method, device and system for synchronizing cache data
CN111581238B (en) Information query method and device, electronic equipment and computer readable storage medium
CN106899651B (en) Communication processing method, system and network communication system
CN112437148B (en) Service request processing method and device, service server and system
CN110708402A (en) Accessible resource display method and device and resource access system
KR101846778B1 (en) Method for ID Resolution Service and M2M System applying the same
CN112699160A (en) Metadata template upgrading method and device and readable storage medium
CN112989255B (en) Identification analysis system
CN111309693A (en) Data synchronization method, device and system, electronic equipment and storage medium
US8572231B2 (en) Variable-length nonce generation
CN112887447A (en) Domain name query method and device and domain name server
CN107679093B (en) Data query method and device
CN111400327A (en) Data synchronization method and device, electronic equipment and storage medium
KR101913013B1 (en) System and method for gs1 based thing information searching service
CN114449044B (en) CDN cache verification method and device and electronic equipment
CN112787850B (en) Method, system, device and storage medium for adjusting query rate per second
CN115391293B (en) File acquisition method, device, server and storage medium
US9798785B2 (en) Apparatus and method for searching for address book information
CN112732757B (en) Method, system, device, equipment and storage medium for processing degraded data

Legal Events

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