CN111694869A - Method and device for querying data - Google Patents

Method and device for querying data Download PDF

Info

Publication number
CN111694869A
CN111694869A CN202010549392.2A CN202010549392A CN111694869A CN 111694869 A CN111694869 A CN 111694869A CN 202010549392 A CN202010549392 A CN 202010549392A CN 111694869 A CN111694869 A CN 111694869A
Authority
CN
China
Prior art keywords
data
determining
response
hash table
value
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010549392.2A
Other languages
Chinese (zh)
Inventor
高雪松
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Tongbang Zhuoyi Technology Co ltd
Original Assignee
Beijing Tongbang Zhuoyi 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 Tongbang Zhuoyi Technology Co ltd filed Critical Beijing Tongbang Zhuoyi Technology Co ltd
Priority to CN202010549392.2A priority Critical patent/CN111694869A/en
Publication of CN111694869A publication Critical patent/CN111694869A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables

Abstract

The embodiment of the disclosure discloses a method and a device for querying data. One embodiment of the method comprises: receiving a data acquisition request, wherein the data acquisition request comprises a key value of data to be acquired; determining whether data matched with the key value of the data to be acquired exists in the local hash table cache or not based on the data acquisition request; and responding to the fact that the data matched with the key value of the data to be acquired exists in the local hash table cache, and sending the matched data. The embodiment realizes efficient and stable access of data by using the local hash table cache.

Description

Method and device for querying data
Technical Field
The embodiment of the disclosure relates to the technical field of computers, in particular to a method and a device for querying data.
Background
With the development of computer technology and the internet, the size of data is also getting larger. Computer application systems often need to read large amounts of configuration data during operation, and the configuration information is usually persisted in database systems.
In the prior art, data is generally accessed in a real-time reading mode or a cache cluster mode, which causes overlarge resource overhead during large-scale data reading or needs a complex strategy to ensure the data consistency of distributed caches after configuration updating.
Disclosure of Invention
In order to solve the problem of efficient and stable access to large-scale data, embodiments of the present disclosure propose a method and apparatus for querying data.
In a first aspect, an embodiment of the present disclosure provides a method for querying data, the method including: receiving a data acquisition request, wherein the data acquisition request comprises a key-value of data to be acquired; determining whether data matched with key values of the data to be acquired exist in a local hash table cache or not based on the data acquisition request; and responding to the fact that the data matched with the key value of the data to be acquired exists in the cache of the local hash table, and sending the matched data.
In some embodiments, the data obtaining request further includes a callback function for obtaining data, where the callback function is used to obtain data corresponding to the data obtaining request; and the method further comprises: and calling a callback function in response to determining that no data matched with the key value of the data to be acquired exists in the cache of the local hash table.
In some embodiments, the method further comprises: determining whether the call-back function is successfully called; in response to determining that the call of the callback function is successful, determining whether a result returned by the callback function includes data indicated by the data acquisition request; and in response to determining that the result returned by the callback function includes the data indicated by the data acquisition request, storing the data indicated by the data acquisition request into a local hash table cache, and sending the data indicated by the data acquisition request.
In some embodiments, the local hash table cache includes a key value and a corresponding data encapsulation packet, where the data encapsulation packet includes a data expiration time, an expiration handling type, and data, and the expiration handling type includes backup or destruction.
In some embodiments, the determining whether data matching a key value of the data to be obtained exists in the local hash table cache based on the data obtaining request includes: extracting parameters from the data acquisition request for parameter verification; responding to the parameter verification, and inquiring whether a value matched with a key value of the data to be acquired exists in the local hash table cache or not; in response to determining that a matched value exists, determining whether data corresponding to the matched value is expired according to the data expiration time corresponding to the matched value; in response to determining that the corresponding data is not expired, determining that data matched with key values of the data to be acquired exists in the cache of the local hash table; and in response to determining that no matching value exists or the corresponding data is expired, determining that no data matching the key value of the data to be acquired exists in the local hash table cache.
In some embodiments, the method further comprises: in response to determining that the callback function fails to call or the result returned by the callback function does not include the data indicated by the data acquisition request, determining that a value matched with the key value of the data does not exist in the local hash table cache; responding to the determined value without matching, and sending return information representing that the data to be acquired does not exist; in response to determining that there is a matching value, obtaining an expiration treatment type corresponding to the matching value; in response to determining that the expiration treatment type is backup, sending data corresponding to the matched value; in response to determining that the type of past due treatment is destruction, sending return information characterizing the absence of data to be acquired.
In some embodiments, the method further comprises: and traversing the local hash table cache periodically, and deleting the data with the expired disposal type being destroyed according to the data expiration time.
In a second aspect, an embodiment of the present disclosure provides an apparatus for querying data, the apparatus including: the data acquisition unit is configured to receive a data acquisition request, wherein the data acquisition request comprises a key value of data to be acquired; a determining unit configured to determine whether data matching a key value of the data to be acquired exists in the local hash table cache based on the data acquisition request; a sending unit configured to send the matched data in response to determining that there is data in the local hash table cache that matches the key value of the data to be obtained.
In some embodiments, the data obtaining request further includes a callback function for obtaining data, where the callback function is used to obtain data corresponding to the data obtaining request; and the apparatus further comprises: and the calling unit is configured to call the callback function in response to determining that no data matched with the key value of the data to be acquired exists in the local hash table cache.
In some embodiments, the apparatus further comprises: a call result determination unit configured to determine whether the callback function is successfully called; a first call determination unit configured to determine whether data indicated by the data acquisition request is included in a result returned by the callback function in response to a determination that the callback function is successfully called; the first returning unit is configured to respond to the fact that the data indicated by the data obtaining request is included in the returned result of the callback function, store the data indicated by the data obtaining request into the local hash table cache, and send the data indicated by the data obtaining request.
In some embodiments, the local hash table cache includes a key value and a corresponding data encapsulation packet, where the data encapsulation packet includes a data expiration time, an expiration handling type, and data, and the expiration handling type includes backup or destruction.
In some embodiments, the determining unit includes: the verification module is configured to extract parameters from the data acquisition request for parameter verification; a query module configured to query whether a value matching a key value of the data to be acquired exists in the local hash table cache in response to determining that the parameter verification passes; a first determination module configured to determine, in response to determining that there is a matching value, whether data corresponding to the matching value is expired according to a data expiration time corresponding to the matching value; a second determining module configured to determine that data matching a key value of the data to be acquired exists in the local hash table cache in response to determining that the corresponding data is not expired; a third determining module configured to determine that no data matching the key value of the data to be obtained exists in the local hash table cache in response to determining that no matching value exists or the corresponding data is expired.
In some embodiments, the apparatus further comprises: a second call determination unit configured to determine that a value matching a key value of the data does not exist in the local hash table cache in response to determining that the callback function fails to call or that the data indicated by the data acquisition request is not included in a result returned by the callback function; a second returning unit configured to send, in response to determining that there is no matching value, return information representing that there is no data to be acquired; an acquisition unit configured to acquire an expiration treatment type corresponding to a matched value in response to determining that the matched value exists; a third return unit configured to send data corresponding to the matched value in response to determining that the overdue handling type is backup; a fourth returning unit configured to send return information characterizing that the data to be acquired does not exist in response to determining that the type of the past due treatment is destruction.
In some embodiments, the apparatus further comprises: and the deleting unit is configured to traverse the local hash table cache periodically and delete the data with the expired disposal type being destroyed according to the data expiration time.
In a third aspect, an embodiment of the present disclosure provides a server, including: one or more processors; a storage device having one or more programs stored thereon; when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the method as described in any implementation of the first aspect.
In a fourth aspect, embodiments of the present disclosure provide a computer-readable medium on which a computer program is stored, which when executed by a processor implements the method as described in any of the implementations of the first aspect.
According to the method and the device for querying data, whether the data matched with the key value of the data to be obtained in the received data obtaining request exists or not is queried in the local hash table cache, the matched data can be directly sent when the matched data exists in the hash table, and interaction with a back-end database is not needed in each data access. And the local hash table cache eliminates the network instability factor, and can realize timely application after configuration change without ensuring the consistency of the distributed cache through a complex strategy, thereby realizing high-efficiency and stable access of data by utilizing the local hash table cache.
Drawings
Other features, objects and advantages of the disclosure will become more apparent upon reading of the following detailed description of non-limiting embodiments thereof, made with reference to the accompanying drawings in which:
FIG. 1 is an exemplary system architecture diagram in which one embodiment of the present disclosure may be applied;
FIG. 2 is a flow diagram for one embodiment of a method for querying data, according to the present disclosure;
FIG. 3 is a schematic diagram of one application scenario of a method for querying data in accordance with an embodiment of the present disclosure;
FIG. 4 is a flow diagram of yet another embodiment of a method for querying data according to the present disclosure;
FIG. 5 is a schematic block diagram illustrating one embodiment of an apparatus for querying data according to the present disclosure;
FIG. 6 is a schematic structural diagram of an electronic device suitable for use in implementing embodiments of the present disclosure.
Detailed Description
The present disclosure is described in further detail below with reference to the accompanying drawings and examples. It is to be understood that the specific embodiments described herein are merely illustrative of the relevant invention and not restrictive of the invention. It should be noted that, for convenience of description, only the portions related to the related invention are shown in the drawings.
It should be noted that, in the present disclosure, the embodiments and features of the embodiments may be combined with each other without conflict. The present disclosure will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
Fig. 1 illustrates an exemplary architecture 100 to which the method for querying data or the apparatus for querying data of the present disclosure may be applied.
As shown in fig. 1, the system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, to name a few.
The terminal devices 101, 102, 103 interact with a server 105 via a network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as a web browser application, a shopping-like application, a search-like application, an instant messaging tool, a mailbox client, social platform software, database software, and the like.
The terminal apparatuses 101, 102, and 103 may be hardware or software. When the terminal devices 101, 102, 103 are hardware, they may be various electronic devices having a display screen and supporting the operation of the database, including but not limited to smart phones, tablet computers, e-book readers, MP3 players (Moving Picture Experts Group Audio Layer III, mpeg compression standard Audio Layer 3), MP4 players (Moving Picture Experts Group Audio Layer IV, mpeg compression standard Audio Layer 4), laptop portable computers, desktop computers, and the like. When the terminal apparatuses 101, 102, 103 are software, they can be installed in the electronic apparatuses listed above. It may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services) or as a single piece of software or software module. And is not particularly limited herein.
The server 105 may be a server providing various services, such as a background server providing support for terminal applications displayed on the terminal devices 101, 102, 103. The background server may analyze and the like the received data acquisition request, and feed back a processing result (such as data to be acquired) to the terminal device.
It should be noted that the data acquisition request may also be sent by an application system local to the server, and the server 105 may directly send the data to be acquired to the local application system, in this case, the terminal devices 101, 102, and 103 and the network 104 may not exist.
The server may be hardware or software. When the server is hardware, it may be implemented as a distributed server cluster formed by multiple servers, or may be implemented as a single server. When the server is software, it may be implemented as multiple pieces of software or software modules (e.g., software or software modules used to provide distributed services), or as a single piece of software or software module. And is not particularly limited herein.
It should be noted that the method for querying data provided by the embodiment of the present disclosure is generally performed by the server 105, and accordingly, the apparatus for querying data is generally disposed in the server 105. It should be noted that the terminal devices 101, 102, and 103 may also execute the method for querying data; accordingly, the means for querying data may also be provided in the terminal devices 101, 102, 103.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
With continued reference to FIG. 2, a flow 200 of one embodiment of a method for querying data in accordance with the present disclosure is shown. The method for querying data comprises the following steps:
step 201, a data acquisition request is received.
In this embodiment, the execution subject of the method for querying data (e.g., the server 105 shown in fig. 1) may receive the data acquisition request through a wired connection or a wireless connection. The data obtaining request may include a key value of the data to be obtained. The key value of the data to be acquired can be used for quickly searching whether corresponding data exists in the memory hash table cache.
In this embodiment, as an example, the execution subject may receive a data acquisition request sent by a local application. As yet another example, the execution main body may receive a data acquisition request transmitted by an electronic device (e.g., the terminal device shown in fig. 1) communicatively connected thereto.
In some optional implementation manners of this embodiment, the data obtaining request may further include a callback function for obtaining data. The callback function may be configured to acquire data corresponding to the data acquisition request. In practice, the callback function is usually used to indicate another (other than the local cache) acquisition route of the data to be acquired indicated by the data acquisition request. The callback function is typically provided by the principal sending the data acquisition request (e.g., the local application or the communicatively coupled device).
Step 202, determining whether data matched with the key value of the data to be acquired exists in the local hash table cache based on the data acquisition request.
In this embodiment, based on the data obtaining request obtained in step 201, the execution main body may determine whether data matching the key value of the data to be obtained included in the data obtaining request exists in the local hash table cache in various ways. As an example, the executing body may first determine, by using a preset hash function, a hash value corresponding to a key value of the data to be acquired. Thereafter, the execution body may perform a collision in the local hash table according to the determined hash value to determine whether there is data matching the hash value.
In some optional implementation manners of this embodiment, the local hash table cache may include a key value and a corresponding data encapsulation packet. The data encapsulation packet may include a data expiration time, an expiration handling type, and data. The above-mentioned type of expiration handling includes a type characterizing "backup" or "destruction". Typically, the expiration handling type may be pre-specified when stored in the local hash table cache.
Based on the optional implementation manner, the execution main body may determine whether data matching the key value of the data to be acquired exists in the local hash table cache according to the following steps:
firstly, parameters are extracted from the data acquisition request for parameter verification.
In these implementations, the execution body may extract a key value from the data acquisition request for parameter verification. Wherein, the parameter verification may include but is not limited to at least one of the following: and determining whether the key value belongs to a preset effective character or not, and determining whether the length of the key value meets a preset requirement or not. Optionally, the data obtaining request may further include cache time information used for indicating a valid time of the data. Correspondingly, the parameter verification may further include determining whether the time indicated by the buffering time information satisfies a current time requirement.
And secondly, responding to the fact that the parameter verification is passed, and inquiring whether a value matched with the key value of the data to be acquired exists in the local hash table cache or not.
In these implementations, in response to determining that the parameter verification of the first step passes, the execution main body may query whether a value matching the key value of the data to be acquired exists in the local hash table cache in a manner of collision with the hash value consistent with the foregoing step.
And thirdly, responding to the fact that the matched value exists, and determining whether the data corresponding to the matched value is expired or not according to the data expiration time corresponding to the matched value.
In these implementations, the execution body may determine whether the data corresponding to the matched value is expired in various ways according to the data expiration time corresponding to the matched value. As an example, the execution body may determine whether the data is expired by determining whether a current time reaches a data expiration time corresponding to the matched value.
And fourthly, in response to the fact that the corresponding data is not expired, determining that data matched with the key value of the data to be acquired exists in the cache of the local hash table.
And fifthly, in response to the fact that the matched value does not exist or the corresponding data is expired, determining that the data matched with the key value of the data to be acquired does not exist in the cache of the local hash table.
Based on the optional implementation manner, the timeliness of the data read from the local hash table cache can be guaranteed.
Step 203, in response to determining that data matching the key value of the data to be acquired exists in the local hash table cache, sending the matched data.
In this embodiment, in response to determining that data matching the key value of the data to be acquired exists in the local hash table cache, the execution main body may send the matching data to the electronic device sending the data acquisition request.
In some optional implementation manners of this embodiment, based on a callback function of the acquired data included in the data acquisition request, in response to determining that no data matching the key value of the data to be acquired exists in the local hash table cache, the execution main body may further call the callback function.
Based on the optional implementation manner, the execution main body may provide another data acquisition manner besides the local hash table cache, so as to increase the success rate of data acquisition.
In some optional implementation manners of this embodiment, based on the call of the callback function, the execution main body may continue to perform the following steps:
in the first step, in response to determining that the call of the callback function is successful, it is determined whether a result returned by the callback function includes data indicated by the data acquisition request.
In these implementations, the execution principal may determine whether the returned result includes the data indicated by the data obtaining request by determining whether the result returned by the callback function is null. In general, in response to determining that the returned result is not null, the execution principal may determine that the data indicated by the data obtaining request is included in the returned result of the callback function.
And secondly, in response to the fact that the result returned by the callback function includes the data indicated by the data acquisition request, storing the data indicated by the data acquisition request into a local hash table for caching, and sending the data indicated by the data acquisition request.
In these implementations, in response to determining that the result returned by the callback function includes the data indicated by the data obtaining request, the execution main body may store the data indicated by the data obtaining request in the local hash table cache, and send the data indicated by the data obtaining request. Optionally, based on the key value and the corresponding data encapsulation packet included in the local hash table cache, the execution main body may store the data indicated by the data acquisition request into the local hash table cache after performing corresponding encapsulation on the data. The packaging mode is consistent with the data format in the local hash table cache.
In some optional implementation manners of this embodiment, the executing body may further traverse the local hash table cache periodically, and delete the data whose expiration handling type is the type that characterizes "destruction" according to the data expiration time of the data encapsulation packet in the local hash table cache.
Based on the optional implementation mode, the timeliness and the cache hit rate of the data in the cache of the local hash table can be improved.
With continued reference to fig. 3, fig. 3 is a schematic diagram of an application scenario of a method for querying data according to an embodiment of the present disclosure. In the application scenario of fig. 3, the local hash table cache 302 of the electronic device receives a configuration data acquisition request 303 sent by an application 301. Then, based on the key value of the to-be-acquired configuration data included in the configuration data acquisition request 303, the electronic device may determine whether the local hash table cache 302 has configuration data matching the key value of the to-be-acquired configuration data. In response to determining that the configuration data matching the key value of the configuration data to be obtained exists in the local hash table cache 302, the electronic device may send the configuration data 304 in the local hash table cache 302 to the application 301.
At present, one of the prior arts generally employs real-time reading or a cache cluster manner for data access, which results in excessive resource overhead during large-scale data reading or needs to perform cache synchronization after configuration update. The method provided by the embodiment of the disclosure does not need to interact with the back-end database every time of data access through the local hash table cache, eliminates the network instability factor through the local hash table cache, and can realize timely application after configuration change without ensuring the consistency of the distributed cache through a complex strategy. Therefore, efficient and stable access of data is realized by using the local hash table cache.
With further reference to FIG. 4, a flow 400 of yet another embodiment of a method for querying data is illustrated. The process 400 of the method for querying data includes the steps of:
step 401, a data acquisition request is received.
In this embodiment, the data obtaining request may include a key value of the data to be obtained and a callback function of the obtained data. The callback function may be configured to acquire data corresponding to the data acquisition request.
Step 402, determining whether data matched with the key value of the data to be acquired exists in the local hash table cache or not based on the data acquisition request.
In this embodiment, the local hash table cache may include a key value and a corresponding data encapsulation packet. The data encapsulation packet may include a data expiration time, an expiration handling type, and data. The above-mentioned type of expiration handling may include a type for characterizing "backup" or "destruction". In general, the matching data may include data having a match between a key value and a data expiration time.
Step 403, in response to determining that data matching the key value of the data to be acquired exists in the local hash table cache, sending the matched data.
Step 404, in response to determining that no data matching the key value of the data to be obtained exists in the local hash table cache, a callback function is invoked.
Step 401, step 402, step 403, and step 404 may be respectively consistent with step 201, step 202, step 203, and optional implementations thereof in the foregoing embodiment, and the above description on step 201, step 202, step 203, and optional implementations thereof is also applicable to step 401, step 402, step 403, and step 404, and is not described herein again.
Step 405, in response to determining that the callback function fails to call or the result returned by the callback function does not include the data indicated by the data acquisition request, determining that a value matching the key value of the data does not exist in the local hash table cache.
In this embodiment, in response to determining that the callback function fails to call or the result returned by the callback function does not include the data indicated by the data acquisition request, the execution subject of the method for querying data (e.g., the server 105 shown in fig. 1) may determine that no value matching the key value of the data exists in the local hash table cache. In general, in response to determining that the returned result is a null value, the execution principal may determine that the callback function returns a result that does not include the data indicated by the data acquisition request.
Step 406, in response to determining that there is no matching value, sending a return message indicating that there is no data to be acquired;
in this embodiment, in response to determining that there is no matching value, the executing body may send return information representing that there is no data to be acquired to the electronic device that sent the data acquisition request.
In response to determining that there is a matching value, an expiration treatment type corresponding to the matching value is obtained, step 407.
In this embodiment, in response to determining that there is a matching value, the execution subject may obtain an expiration treatment type corresponding to the matching value. This generally applies to the case where there is data matching the key value but the data expiration time is not satisfactory. Based on the expiration handling type and the data being encapsulated in the data encapsulation packet cached in the local hash table, the execution body may first obtain the data encapsulation packet corresponding to the matched value. Then, the execution body may obtain an expiration handling type from the corresponding data encapsulation packet.
In response to determining that the expiration disposition type is backup, data corresponding to the matched value is sent, step 408.
In this embodiment, in response to determining that the type of the expiration treatment acquired in step 407 is a type that characterizes "backup", the executing entity may transmit data corresponding to the matched value to the electronic device that sent the data acquisition request. The data corresponding to the matched value may include data in the same data encapsulation packet as the expiration handling type.
Step 409, in response to determining that the overdue disposal type is destruction, sending a return message indicating that the data to be acquired does not exist.
In this embodiment, in response to determining that the expiration treatment type is a type representing "destruction", the execution main body may transmit return information representing that the data to be acquired does not exist to the electronic device that transmitted the data acquisition request.
In some optional implementation manners of this embodiment, the executing body may further traverse the local hash table cache periodically, and delete the data whose expiration handling type is the type that characterizes "destruction" according to the data expiration time of the data encapsulation packet in the local hash table cache.
As can be seen from fig. 4, the flow 400 of the method for querying data in the present embodiment embodies a step of sending return data or characterizing that data does not exist according to an overdue handling type in the case that the callback function fails to call or the data indicated by the data acquisition request is not included in the result returned by the callback function. Therefore, the solution described in this embodiment may return the required data by using the backup data in the local hash table cache, thereby implementing a disaster recovery processing solution for solving the network or data source abnormality by using the backup mechanism.
With further reference to fig. 5, as an implementation of the methods shown in the above-mentioned figures, the present disclosure provides an embodiment of an apparatus for querying data, where the embodiment of the apparatus corresponds to the embodiment of the method shown in fig. 2 or fig. 4, and the apparatus may be specifically applied to various electronic devices.
As shown in fig. 5, the apparatus 500 for querying data provided by the present embodiment includes a receiving unit 501, a determining unit 502, and a sending unit 503. The receiving unit 501 is configured to receive a data obtaining request, where the data obtaining request includes a key value of data to be obtained; a determining unit 502 configured to determine whether data matching a key value of the data to be acquired exists in the local hash table cache based on the data acquisition request; a sending unit 503 configured to send the matched data in response to determining that there is data in the local hash table cache that matches the key value of the data to be obtained.
In the present embodiment, in the apparatus 500 for querying data: specific processing of the receiving unit 501, the determining unit 502, and the sending unit 503 and technical effects thereof may refer to related descriptions of step 201, step 202, and step 203 in the embodiment corresponding to fig. 2 and corresponding steps in the embodiment corresponding to fig. 4, respectively, and are not described herein again.
In some optional implementation manners of this embodiment, the data obtaining request may further include a callback function for obtaining data. The callback function may be used to obtain data corresponding to the data obtaining request. The apparatus 500 for querying data may further include: and the calling unit is configured to call the callback function in response to determining that no data matched with the key value of the data to be acquired exists in the local hash table cache.
In some optional implementations of this embodiment, the apparatus 500 for querying data may further include: a call result determining unit (not shown in the figure), a first call determining unit (not shown in the figure), a first returning unit (not shown in the figure). The call result determining unit may be configured to determine whether the callback function is successfully called. The first call determination unit may be configured to determine whether the result returned by the callback function includes the data indicated by the data acquisition request in response to determining that the callback function is successfully called. The first returning unit may be configured to, in response to determining that the result returned by the callback function includes the data indicated by the data obtaining request, store the data indicated by the data obtaining request in the local hash table cache, and send the data indicated by the data obtaining request.
In some optional implementation manners of this embodiment, the local hash table cache may include a key value and a corresponding data encapsulation packet. The data encapsulation packet may include a data expiration time, an expiration handling type, and data. The type of expiration handling described above may include backup or destruction.
In some optional implementations of this embodiment, the determining unit 502 may include: a verification module (not shown), an inquiry module (not shown), a first determination module (not shown), a second determination module (not shown), and a third determination module (not shown). The verification module may be configured to extract parameters from the data acquisition request for parameter verification. The query module may be configured to query whether a value matching the key value of the data to be acquired exists in the local hash table cache in response to determining that the parameter verification passes. The first determining module may be configured to determine whether data corresponding to the matched value is expired according to a data expiration time corresponding to the matched value in response to determining that the matched value exists. The second determining module may be configured to determine that data matching the key value of the data to be acquired exists in the local hash table cache in response to determining that the corresponding data is not expired. The third determining module may be configured to determine that no data matching the key value of the data to be obtained exists in the local hash table cache in response to determining that no matching value exists or the corresponding data is expired.
In some optional implementations of this embodiment, the apparatus 500 for querying data may further include: a second call determination unit (not shown), a second return unit (not shown), an acquisition unit (not shown), a third return unit (not shown), and a fourth return unit (not shown). The second call determination unit may be configured to determine that a value matching the key value of the data does not exist in the local hash table cache in response to determining that the callback function fails to call or that the result returned by the callback function does not include the data indicated by the data obtaining request. The above-mentioned second returning unit may be configured to send, in response to determining that there is no matching value, return information representing that the data to be acquired does not exist. The above-mentioned obtaining unit may be configured to, in response to determining that there is a matching value, obtain an expiration treatment type corresponding to the matching value. The third returning unit may be configured to send data corresponding to the matched value in response to determining that the expiration treatment type is backup. The fourth returning unit may be configured to send, in response to determining that the expiration treatment type is destruction, return information indicating that the data to be acquired does not exist.
In some optional implementations of this embodiment, the apparatus 500 for querying data may further include: and a deleting unit (not shown in the figure) configured to traverse the local hash table cache periodically and delete the data with the expired disposal type being destroyed according to the data expiration time.
The above embodiments of the present disclosure provide an apparatus that receives a data acquisition request through the receiving unit 501. The data acquisition request comprises a key value of the data to be acquired. Then, the determining unit 502 determines whether data matching the key value of the data to be acquired exists in the local hash table cache based on the data acquisition request. Finally, the sending unit 503 sends the matched data in response to determining that the data matching the key value of the data to be acquired exists in the local hash table cache. Because the data access does not need to interact with a back-end database every time, the network instability factor is eliminated through the local hash table cache, the timely application can be realized after the configuration is changed, the consistency of the distributed cache is not required to be ensured through a complex strategy, and the high-efficiency stable access of the data is realized by utilizing the local hash table cache.
Referring now to FIG. 6, a schematic diagram of an electronic device (e.g., the server of FIG. 1) 600 suitable for use in implementing embodiments of the present disclosure is shown. The terminal device in the embodiments of the present disclosure may include, but is not limited to, a mobile terminal such as a mobile phone, a notebook computer, a digital broadcast receiver, a PDA (personal digital assistant), a PAD (tablet computer), a PMP (portable multimedia player), a vehicle terminal (e.g., a car navigation terminal), and the like, and a fixed terminal such as a digital TV, a desktop computer, and the like. The server shown in fig. 6 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 6, electronic device 600 may include a processing means (e.g., central processing unit, graphics processor, etc.) 601 that may perform various appropriate actions and processes in accordance with a program stored in a Read Only Memory (ROM)602 or a program loaded from a storage means 608 into a Random Access Memory (RAM) 603. In the RAM603, various programs and data necessary for the operation of the electronic apparatus 600 are also stored. The processing device 601, the ROM 602, and the RAM603 are connected to each other via a bus 604. An input/output (I/O) interface 605 is also connected to bus 604.
Generally, the following devices may be connected to the I/O interface 605: input devices 606 including, for example, a touch screen, touch pad, keyboard, mouse, etc.; an output device 607 including, for example, a Liquid Crystal Display (LCD), a speaker, a vibrator, and the like; storage 608 including, for example, tape, hard disk, etc.; and a communication device 609. The communication means 609 may allow the electronic device 600 to communicate with other devices wirelessly or by wire to exchange data. While fig. 6 illustrates an electronic device 600 having various means, it is to be understood that not all illustrated means are required to be implemented or provided. More or fewer devices may alternatively be implemented or provided. Each block shown in fig. 6 may represent one device or may represent multiple devices as desired.
In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method illustrated in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication means 609, or may be installed from the storage means 608, or may be installed from the ROM 602. The computer program, when executed by the processing device 601, performs the above-described functions defined in the methods of embodiments of the present disclosure.
It should be noted that the computer readable medium described in the embodiments of the present disclosure may be a computer readable signal medium or a computer readable storage medium or any combination of the two. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples of the computer readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In embodiments of the disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In embodiments of the present disclosure, however, a computer readable signal medium may comprise a propagated data signal with computer readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to: electrical wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the foregoing.
The computer readable medium may be embodied in the server; or may exist separately and not be assembled into the server. The computer readable medium carries one or more programs which, when executed by the server, cause the server to: receiving a data acquisition request, wherein the data acquisition request comprises a key value of data to be acquired; determining whether data matched with key values of the data to be acquired exist in a local hash table cache or not based on the data acquisition request; and responding to the fact that the data matched with the key value of the data to be acquired exists in the cache of the local hash table, and sending the matched data.
Computer program code for carrying out operations for embodiments of the present disclosure may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, Smalltalk, C + +, and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or the connection may be made to an external computer (for example, through the Internet using an Internet service provider).
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units described in the embodiments of the present disclosure may be implemented by software or hardware. The described units may also be provided in a processor, and may be described as: a processor includes a receiving unit, a determining unit, and a transmitting unit. The names of these units do not in some cases form a limitation on the units themselves, and for example, the receiving unit may also be described as a unit that receives a data acquisition request including a key value of data to be acquired.
The foregoing description is only exemplary of the preferred embodiments of the disclosure and is illustrative of the principles of the technology employed. It will be appreciated by those skilled in the art that the scope of the invention in the embodiments of the present disclosure is not limited to the specific combination of the above-mentioned features, but also encompasses other embodiments in which any combination of the above-mentioned features or their equivalents is made without departing from the inventive concept as defined above. For example, the above features and (but not limited to) technical features with similar functions disclosed in the embodiments of the present disclosure are mutually replaced to form the technical solution.

Claims (15)

1. A method for querying data, comprising:
receiving a data acquisition request, wherein the data acquisition request comprises a key value of data to be acquired;
determining whether data matched with key values of the data to be acquired exist in a local hash table cache or not based on the data acquisition request;
and responding to the fact that the data matched with the key value of the data to be acquired exists in the local hash table cache, and sending the matched data.
2. The method according to claim 1, wherein the data acquisition request further includes a callback function for acquiring data, and the callback function is used for acquiring data corresponding to the data acquisition request; and
the method further comprises the following steps:
and calling the callback function in response to determining that no data matched with the key value of the data to be acquired exists in the local hash table cache.
3. The method of claim 2, wherein the method further comprises:
determining whether the callback function is successfully called;
in response to determining that the callback function is successfully called, determining whether the result returned by the callback function includes the data indicated by the data acquisition request;
and in response to the fact that the result returned by the callback function includes the data indicated by the data acquisition request, storing the data indicated by the data acquisition request into the local hash table cache, and sending the data indicated by the data acquisition request.
4. The method of claim 2, wherein the local hash table cache comprises key values and corresponding data encapsulation packets, the data encapsulation packets comprise data expiration times, expiration handling types and data, and the expiration handling types comprise backup or destruction.
5. The method of claim 4, wherein the determining whether data matching a key value of the data to be obtained exists in a local hash table cache based on the data obtaining request comprises:
extracting parameters from the data acquisition request for parameter verification;
in response to the fact that the parameter verification is confirmed to be passed, whether a value matched with the key value of the data to be acquired exists in the local hash table cache or not is inquired;
in response to determining that the matched value exists, determining whether data corresponding to the matched value is expired according to the data expiration time corresponding to the matched value;
in response to determining that the corresponding data is not expired, determining that data matched with the key value of the data to be acquired exists in the local hash table cache;
and in response to determining that the matched value does not exist or the corresponding data is expired, determining that data matched with the key value of the data to be acquired does not exist in the local hash table cache.
6. The method of claim 4, wherein the method further comprises:
in response to determining that the callback function fails to call or the result returned by the callback function does not include the data indicated by the data acquisition request, determining that a value matching the key value of the data does not exist in the local hash table cache;
in response to determining that the matched value does not exist, sending return information representing that the data to be acquired does not exist;
in response to determining that the matched value exists, obtaining an overdue treatment type corresponding to the matched value;
in response to determining that the stale handling type is a backup, sending data corresponding to the matched value;
in response to determining that the type of past due treatment is destruction, sending return information characterizing the absence of data to be acquired.
7. The method according to one of claims 4-6, wherein the method further comprises:
and traversing the local hash table cache periodically, and deleting the data with the expired disposal type being destroyed according to the data expiration time.
8. An apparatus for querying data, comprising:
the data acquisition unit is configured to receive a data acquisition request, wherein the data acquisition request comprises a key value of data to be acquired;
a determining unit configured to determine whether data matching a key value of the data to be acquired exists in a local hash table cache based on the data acquisition request;
a sending unit configured to send the matched data in response to determining that there is data in the local hash table cache that matches a key value of the data to be obtained.
9. The apparatus according to claim 8, wherein the data acquisition request further includes a callback function for acquiring data, and the callback function is configured to acquire data corresponding to the data acquisition request; and
the device further comprises:
a calling unit configured to call the callback function in response to determining that no data matching the key value of the data to be acquired exists in the local hash table cache.
10. The apparatus of claim 9, wherein the apparatus further comprises:
a call result determination unit configured to determine whether the callback function is successfully called;
a first call determination unit configured to determine whether data indicated by the data acquisition request is included in a result returned by the callback function in response to a determination that the callback function is successfully called;
a first returning unit configured to store the data indicated by the data obtaining request into the local hash table cache and send the data indicated by the data obtaining request in response to determining that the data indicated by the data obtaining request is included in the result returned by the callback function.
11. The apparatus of claim 9, wherein the local hash table cache includes a key value and a corresponding data encapsulation packet, the data encapsulation packet includes a data expiration time, an expiration handling type, and data, and the expiration handling type includes backup or destruction.
12. The apparatus of claim 11, wherein the determining unit comprises:
the verification module is configured to extract parameters from the data acquisition request for parameter verification;
a query module configured to query whether a value matching a key value of the data to be obtained exists in the local hash table cache in response to determining that the parameter verification passes;
a first determination module configured to determine, in response to determining that the matched value exists, whether data corresponding to the matched value is expired according to a data expiration time corresponding to the matched value;
a second determining module configured to determine that data matching the key value of the data to be obtained exists in the local hash table cache in response to determining that the corresponding data is not expired;
a third determining module configured to determine that no data matching the key value of the data to be obtained exists in the local hash table cache in response to determining that the matching value does not exist or the corresponding data is expired.
13. The apparatus of claim 11, wherein the apparatus further comprises:
a second call determination unit configured to determine that a value matching a key value of the data does not exist in the local hash table cache in response to determining that the callback function fails to call or that the data indicated by the data acquisition request is not included in the result returned by the callback function;
a second returning unit configured to send, in response to determining that there is no value of the match, return information representing that there is no data to be acquired;
an obtaining unit configured to obtain an expiration treatment type corresponding to the matched value in response to determining that the matched value exists;
a third return unit configured to send data corresponding to the matched value in response to determining that the stale handling type is a backup;
a fourth returning unit configured to send return information characterizing that the data to be acquired does not exist in response to determining that the type of the past due treatment is destruction.
14. A server, comprising:
one or more processors;
a storage device having one or more programs stored thereon;
when executed by the one or more processors, cause the one or more processors to implement the method of any one of claims 1-7.
15. A computer-readable medium, on which a computer program is stored which, when being executed by a processor, carries out the method according to any one of claims 1-7.
CN202010549392.2A 2020-06-16 2020-06-16 Method and device for querying data Pending CN111694869A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010549392.2A CN111694869A (en) 2020-06-16 2020-06-16 Method and device for querying data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010549392.2A CN111694869A (en) 2020-06-16 2020-06-16 Method and device for querying data

Publications (1)

Publication Number Publication Date
CN111694869A true CN111694869A (en) 2020-09-22

Family

ID=72481459

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010549392.2A Pending CN111694869A (en) 2020-06-16 2020-06-16 Method and device for querying data

Country Status (1)

Country Link
CN (1) CN111694869A (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108804447A (en) * 2017-04-28 2018-11-13 北京京东尚科信息技术有限公司 Utilize the method and system of cache responses request of data
CN109657174A (en) * 2018-12-25 2019-04-19 北京百度网讯科技有限公司 Method and apparatus for more new data
CN109766362A (en) * 2018-12-28 2019-05-17 北京字节跳动网络技术有限公司 Data processing method and device
CN109885593A (en) * 2019-02-21 2019-06-14 北京字节跳动网络技术有限公司 Method and apparatus for handling information
CN110147368A (en) * 2017-11-27 2019-08-20 北京京东尚科信息技术有限公司 Data capture method and device for server
CN111163156A (en) * 2019-12-26 2020-05-15 山东爱城市网信息技术有限公司 Data processing method, device and storage medium based on block chain

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108804447A (en) * 2017-04-28 2018-11-13 北京京东尚科信息技术有限公司 Utilize the method and system of cache responses request of data
CN110147368A (en) * 2017-11-27 2019-08-20 北京京东尚科信息技术有限公司 Data capture method and device for server
CN109657174A (en) * 2018-12-25 2019-04-19 北京百度网讯科技有限公司 Method and apparatus for more new data
CN109766362A (en) * 2018-12-28 2019-05-17 北京字节跳动网络技术有限公司 Data processing method and device
CN109885593A (en) * 2019-02-21 2019-06-14 北京字节跳动网络技术有限公司 Method and apparatus for handling information
CN111163156A (en) * 2019-12-26 2020-05-15 山东爱城市网信息技术有限公司 Data processing method, device and storage medium based on block chain

Similar Documents

Publication Publication Date Title
US20110238924A1 (en) Webpage request handling
CN111930534A (en) Data calling method and device and electronic equipment
CN111309747A (en) Data synchronization method, system and device
CN112256733A (en) Data caching method and device, electronic equipment and computer readable storage medium
US20190370293A1 (en) Method and apparatus for processing information
CN112181733A (en) Service request processing method, device, equipment and storage medium
CN113553206B (en) Data event execution method and device, electronic equipment and computer readable medium
CN113824675B (en) Method and device for managing login state
CN111460020B (en) Method, device, electronic equipment and medium for resolving message
CN115658171A (en) Method and system for solving dynamic refreshing of java distributed application configuration in lightweight mode
CN111444457B (en) Data release method and device, storage medium and electronic equipment
CN111694869A (en) Method and device for querying data
CN113760929A (en) Data synchronization method and device, electronic equipment and computer readable medium
CN112311843A (en) Data loading method and device
CN112230986A (en) Project file generation method and device, electronic equipment and computer readable medium
CN112163176A (en) Data storage method and device, electronic equipment and computer readable medium
CN112799863A (en) Method and apparatus for outputting information
CN112311842A (en) Method and device for information interaction
CN110795670A (en) Webpage image monitoring method and device, electronic equipment and readable storage medium
CN111787043A (en) Data request method and device
CN112948108B (en) Request processing method and device and electronic equipment
CN110007894B (en) Method and device for transmitting audio information
CN113342837B (en) Data transmission method, device, electronic equipment and computer readable medium
CN113778909B (en) Method and device for caching data
CN110099122B (en) Method and apparatus for sending network request

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