Specific embodiment
To keep the purposes, technical schemes and advantages of the application clearer, below in conjunction with the application specific embodiment and
Technical scheme is clearly and completely described in corresponding attached drawing.Obviously, described embodiment is only the application one
Section Example, instead of all the embodiments.Based on the embodiment in the application, those of ordinary skill in the art are not doing
Every other embodiment obtained under the premise of creative work out, shall fall in the protection scope of this application.
Fig. 1 is data query process provided by the embodiments of the present application, is specifically included:
S101: inquiry request is received.
In the embodiment of the present application, when user will inquire some data, user end to server can be first passed through and send inquiry
Request, wherein the Data Identification that the data to be inquired are carried in the inquiry request makes server by the Data Identification, knows
Which data is the data to be inquired be.The Data Identification generally can be the major key of data.The server can be single
Server, can also be with a server cluster or distributed server.
S102: according to the Data Identification carried in the inquiry request, and the first Bloom filter pre-saved, judgement
The corresponding data of the Data Identification whether there is, if so, thening follow the steps S103, otherwise, execute step S104.
In the embodiment of the present application, server has pre-saved the first Bloom filter, which is pre-
First generated according to all data stored in database.Pass through the Data Identification and first cloth carried in inquiry request
Grand filter, server can judge that the corresponding data of the Data Identification whether there is in database.
Specifically, generating the specific method of Bloom filter is: default n Serial No.s, each is 0, presets k
A hash function, the codomain of each hash function are that 0~n, n and k are natural number, for the every number saved in database
According to Data Identification, the Data Identification of the data is inputted into this k hash function respectively, k hashed value is obtained, is denoted as respectively
H1, H2, H3 ... Hk, then by H1 in n bit digital sequence, H2, H3 ... Hk bit digital is set to 1,
In this way, be equivalent to the Data Identification " input " of data Bloom filter, method is by data all in database according to this
Data Identification all input Bloom filter after, just obtained the first Bloom filter described in the embodiment of the present application.That is,
Bloom filter described in the embodiment of the present application specifically includes: n bit digital sequence (being made of 0 or 1) and k hash letter
Number.
After server receives inquiry request by step S101, according to the Data Identification carried in the inquiry request and
First Bloom filter judges the corresponding data of the Data Identification with the presence or absence of the method in database are as follows: by the inquiry
The Data Identification carried in request inputs this k hash function respectively, obtains k hashed value, be denoted as respectively L1, L2, L3 ...
Lk, in n bit digital sequence, judge respectively L1, L2, L3 ... whether Lk numbers are 1, if
It is 1, it is determined that the corresponding data of the Data Identification are present in database, if at least one is not 1, it is determined that the Data Identification
Corresponding data are not present in database.
S103: obtaining and returns to the data.
If the server determine that data exist, then the corresponding data of the Data Identification can be inquired from database and are returned to
Client.
S104: inquiry failure is determined.
It if the server determine that data are not present, then can determine that this inquiry is looked into for sky, and then determine this inquiry failure,
The prompt information of inquiry failure can be returned to client.
Judge method that data whether there is by the generation method of above-mentioned Bloom filter and based on Bloom filter as it can be seen that
Bloom filter is not really data all to be stored, but be only to record data with one n Serial No.s
No presence, therefore, server are directed to an inquiry request, only need to can judge whether it is empty according to the Bloom filter
It looks into, if not sky is looked into, then inquires data from database, otherwise, can no longer be inquired from database, therefore can effectively avoid sky
It checks database and causes unnecessary pressure, reduce database overhead, improve search efficiency.
Certainly, by the generation method of above-mentioned Bloom filter it can also be seen that, for the data being present in database, pass through
Bloom filter must can determine that it is present in database, for the data being not present in database, due to hash
The characteristic of function itself is also possible to be mistaken for being present in database by Bloom filter, still, this False Rate
(also referred to as false percent of pass) can be calculated by above-mentioned n and k, that is to say, that by adjusting the value of n and k, can make to judge by accident
Rate is reduced to acceptable range hereinafter, such as False Rate is made to be reduced to one thousandth or less.
In addition, into Bloom filter, input data is very convenient for common Bloom filter, but
It is that " deletion " data are more difficult from Bloom filter, for example, it is assumed that delete some data in database, then phase
It answers, the Data Identification of " deletion " data is also answered in the first Bloom filter in the embodiment of the present application, but if simply
By the Data Identification corresponding H1 in n bit digital sequence, H2, H3 ... it is aobvious that Hk numbers are set to 0
It is so improper, this is because can may also correspond to H1, H2, the after other Data Identifications input k hash function
H3 ... in Hk some or certain it is several, therefore, in the embodiment of the present application, follow-on cloth also can be used
Grand filter, follow-on Bloom filter are mainly that the number for setting 1 to each bit digital in n bit digital sequence is remembered
The data when " deletion " data, can be subtracted 1 in the number that the corresponding each bit digital of n bit digital sequence sets 1 by record, right
For n bit digital sequence one-bit digital, if the number that this bit of data is set to 1 is 0, which is changed to 0, this
Sample can easily delete data from Bloom filter.
In step S103 shown in Fig. 1, server determines that the corresponding data of the Data Identification carried in inquiry request are deposited
After being in database, when obtaining and returning to the data, the data can be first searched in the caching of itself and are obtained if finding
It takes and returns to the data, if not finding, search the data in the database, and the data found are returned into client
End.Due to server from own cache search data speed will far faster than from database search data speed,
Server priority searches data from the caching of itself, can further improve the efficiency for searching data.
Certainly, when server does not find data in the caching of itself, but finds the data in the database, also
The data found can be written in the caching of itself, it, can be from the caching of itself directly when inquiring the data so as to next time
It finds.
It further, can also be according to pre-saving the second cloth when searching data in the caching of itself when server priority
Grand filter is searched, second Bloom filter be generated previously according to all data stored in caching, specifically,
Server can be according to the Data Identification carried in inquiry request, and the second Bloom filter pre-saved judges the data
Identifying corresponding data whether there is in caching, if so, obtain the data from caching and return to client, otherwise,
The data are searched in the database, and the data found are returned into client.Certainly, if according to the second Bloom filter
When determining that the data are not present in caching, and finding from database the data, when searching the data for the ease of next time
It can directly be found from caching, the data found can be also written in the caching of itself by server, and should according to write-in
All data stored in caching after data update the second Bloom filter.
The generation method and application method of above-mentioned second Bloom filter are similar, the two with the first Bloom filter
Difference is only that the first Bloom filter is generated according to the data stored in database, and the second Bloom filter is according to clothes
The data that store generate in business device caching, here with regard to no longer to the second Bloom filter generation and application method go to live in the household of one's in-laws on getting married
It states.
It should be noted that data query method provided by the embodiments of the present application, which can be applied to high concurrent, inquires more electricity
Sub- business scene, then inquiry request described in the embodiment of the present application includes but is not limited to querying commodity information request, transaction record
Inquiry request etc., the Data Identification include but is not limited to product name, commercial product identification identification code (IDentity, ID) etc.,
The server includes but is not limited to electric business website server, payment server etc..
Fig. 2 is the detailed process of data query provided by the embodiments of the present application, specifically includes the following steps:
S201: server receives inquiry request.
S202: according to the Data Identification carried in inquiry request, and the first Bloom filter pre-saved, judgement should
The corresponding data of Data Identification whether there is, if so, step S203 is executed, it is no to then follow the steps S206.
Wherein, which generated according to all data stored in database.
S203: according to the Data Identification, and the second Bloom filter pre-saved, judge that the Data Identification is corresponding
Data whether there is in caching, if so, step S204 is executed, it is no to then follow the steps S205.
S204: the data are obtained from caching and are returned.
Wherein, which generated according to all data stored in caching.
S205: searching the data in the database and return, and the data found are written in caching, and should according to write-in
All data stored in caching after data update the second Bloom filter.
S206: inquiry failure is determined.
The above are data query methods provided by the embodiments of the present application, are based on same thinking, and the embodiment of the present application also mentions
A kind of data query device is supplied, as shown in Figure 3.
Fig. 3 is data query device structural schematic diagram provided by the embodiments of the present application, is specifically included:
Receiving module 301, for receiving inquiry request;
Memory module 302, for storing the first Bloom filter;
Judgment module 303, for according to the Data Identification carried in the inquiry request, and the first cloth pre-saved
Grand filter judges that the corresponding data of the Data Identification whether there is;
Enquiry module 304 is when being, to obtain and return the data for the judging result in the judgment module 303,
When the judging result of the judgment module 303 is no, inquiry failure is determined.
The memory module 302 is specifically used for, and previously according to all data stored in database, generates corresponding first
Bloom filter simultaneously saves.
The enquiry module 304 is specifically used for, and when the judging result of the judgment module 303 is to be, looks into the buffer
The data are looked for, if finding, obtains and returns to the data, if not finding, search the data in the database,
And the data found are returned.
The enquiry module 304 is also used to, when finding the data in the database, the data that will find
It is written in the caching.
The enquiry module 304 is specifically used for, when the judging result of the judgment module 303 is to be, according to the number
According to mark, and the second Bloom filter pre-saved, judge that the corresponding data of the Data Identification whether there is in caching
In, if so, obtain the data from caching and return, otherwise, search the data in the database, and will find
Data return, wherein second Bloom filter is generated according to all data stored in the caching.
The enquiry module 304 is also used to, when finding the data in the database, the data that will find
It is written in the caching, according to all data stored in the caching after the write-in data, updates the second Bloom filter.
A kind of data query method and apparatus provided by the embodiments of the present application, this method server receive inquiry request
When, only it need to judge that the corresponding data of the Data Identification carried in the inquiry request whether there is according to the Bloom filter prestored,
And the data are only searched and returned in the presence of its, without looking into the Data Identification carried in each inquiry request
It askes, is looked into so as to effectively filter sky, avoid sky from checking database and cause unnecessary pressure, opened to reach and reduce database
Pin, the purpose for promoting search efficiency.
It should be understood by those skilled in the art that, embodiments herein can provide as method, system or computer program
Product.Therefore, complete hardware embodiment, complete software embodiment or reality combining software and hardware aspects can be used in the application
Apply the form of example.Moreover, it wherein includes the computer of computer usable program code that the application, which can be used in one or more,
The computer program implemented in usable storage medium (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.) produces
The form of product.
The application is referring to method, the process of equipment (system) and computer program product according to the embodiment of the present application
Figure and/or block diagram describe.It should be understood that every one stream in flowchart and/or the block diagram can be realized by computer program instructions
The combination of process and/or box in journey and/or box and flowchart and/or the block diagram.It can provide these computer programs
Instruct the processor of general purpose computer, special purpose computer, Embedded Processor or other programmable data processing devices to produce
A raw machine, so that being generated by the instruction that computer or the processor of other programmable data processing devices execute for real
The device for the function of being specified in present one or more flows of the flowchart and/or one or more blocks of the block diagram.
These computer program instructions, which may also be stored in, is able to guide computer or other programmable data processing devices with spy
Determine in the computer-readable memory that mode works, so that it includes referring to that instruction stored in the computer readable memory, which generates,
Enable the manufacture of device, the command device realize in one box of one or more flows of the flowchart and/or block diagram or
The function of being specified in multiple boxes.
These computer program instructions also can be loaded onto a computer or other programmable data processing device, so that counting
Series of operation steps are executed on calculation machine or other programmable devices to generate computer implemented processing, thus in computer or
The instruction executed on other programmable devices is provided for realizing in one or more flows of the flowchart and/or block diagram one
The step of function of being specified in a box or multiple boxes.
In a typical configuration, calculating equipment includes one or more processors (CPU), input/output interface, net
Network interface and memory.
Memory may include the non-volatile memory in computer-readable medium, random access memory (RAM) and/or
The forms such as Nonvolatile memory, such as read-only memory (ROM) or flash memory (flash RAM).Memory is computer-readable medium
Example.
Computer-readable medium includes permanent and non-permanent, removable and non-removable media can be by any method
Or technology come realize information store.Information can be computer readable instructions, data structure, the module of program or other data.
The example of the storage medium of computer includes, but are not limited to phase change memory (PRAM), static random access memory (SRAM), moves
State random access memory (DRAM), other kinds of random access memory (RAM), read-only memory (ROM), electric erasable
Programmable read only memory (EEPROM), flash memory or other memory techniques, read-only disc read only memory (CD-ROM) (CD-ROM),
Digital versatile disc (DVD) or other optical storage, magnetic cassettes, tape magnetic disk storage or other magnetic storage devices
Or any other non-transmission medium, can be used for storage can be accessed by a computing device information.As defined in this article, it calculates
Machine readable medium does not include temporary computer readable media (transitory media), such as the data-signal and carrier wave of modulation.
It should also be noted that, the terms "include", "comprise" or its any other variant are intended to nonexcludability
It include so that the process, method, commodity or the equipment that include a series of elements not only include those elements, but also to wrap
Include other elements that are not explicitly listed, or further include for this process, method, commodity or equipment intrinsic want
Element.In the absence of more restrictions, the element limited by sentence "including a ...", it is not excluded that including described want
There is also other identical elements in the process, method of element, commodity or equipment.
It will be understood by those skilled in the art that embodiments herein can provide as method, system or computer program product.
Therefore, complete hardware embodiment, complete software embodiment or embodiment combining software and hardware aspects can be used in the application
Form.It is deposited moreover, the application can be used to can be used in the computer that one or more wherein includes computer usable program code
The shape for the computer program product implemented on storage media (including but not limited to magnetic disk storage, CD-ROM, optical memory etc.)
Formula.
The above description is only an example of the present application, is not intended to limit this application.For those skilled in the art
For, various changes and changes are possible in this application.All any modifications made within the spirit and principles of the present application are equal
Replacement, improvement etc., should be included within the scope of the claims of this application.