CN106446272A - Method and device for sending data - Google Patents

Method and device for sending data Download PDF

Info

Publication number
CN106446272A
CN106446272A CN201610917492.XA CN201610917492A CN106446272A CN 106446272 A CN106446272 A CN 106446272A CN 201610917492 A CN201610917492 A CN 201610917492A CN 106446272 A CN106446272 A CN 106446272A
Authority
CN
China
Prior art keywords
value
keyword
storage
default
random length
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.)
Granted
Application number
CN201610917492.XA
Other languages
Chinese (zh)
Other versions
CN106446272B (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 Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom 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 Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN201610917492.XA priority Critical patent/CN106446272B/en
Publication of CN106446272A publication Critical patent/CN106446272A/en
Application granted granted Critical
Publication of CN106446272B publication Critical patent/CN106446272B/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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2291User-Defined Types; Storage management thereof

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a method and device for sending data. A specific embodiment of the method comprises the steps that an operation request sent by a user terminal is received, and whether the operation request contains a key word or not is determined, wherein the key word is stored in the form of a preset fixed-length structural body; when it is determined that the operation request contains the key word, the key word is converted into a key word stored in the form of a preset non-fixed-length structural body, and then whether the operation request contains a value corresponding to the key word or not is determined; when it is determined that the operation request does not contain the value, a value which is stored in the form of a preset non-fixed-length structural body and corresponds to the key word stored in the form of the preset non-fixed-length structural body is looked up, the found value stored in the form of the preset non-fixed-length structural body is converted into a value stored in the form of a preset fixed-length structural body, and the converted value is sent to the user terminal. By means of the implementation mode, the memory utilization rate is effectively increased.

Description

Method and apparatus for sending data
Technical field
The application is related to field of computer technology and in particular to technical field of data processing, more particularly, to sends number According to method and apparatus.
Background technology
Key assignments type (Key-Value) data storage storehouse (for example, Redis data storage storehouse), with its high-performance, supports to enrich Data structure the features such as, already take up substantial amounts of market part in NoSQL (Not Only SQL, non-relational database) Volume.When the data of key assignments type data base is stored entirely in internal memory, program itself, in order to support more data structures, is being System design level, in order to versatility has done the compromise on many memory headrooms.And many business, during using, simply make With the storage (i.e. Key-Value storage) of simple String type, under this application scenarios, will result in key assignments type data There is excessive descriptive data structure committed memory in storehouse, causes memory usage low, especially as Key (keyword) and Value When the size of (value) is all smaller, the low problem of memory usage will become more serious, thus wasting a large amount of of server Memory source.
Key-value pair is typically packaged into Hash function at business end by the existing mode improving memory usage, but this The mode of kind requires business side that service code is modified, opaque to the user of key assignments type data base.
Content of the invention
The purpose of the application is to propose a kind of improved method and apparatus for sending data, to solve background above The technical problem that technology segment is mentioned.
In a first aspect, this application provides a kind of method for sending data, methods described includes:In response to receiving The operation requests that user terminal sends, determine whether comprise keyword in described operation requests, wherein, described keyword is with pre- If fixed length structure storage keyword;Keyword is comprised in response to determining, then by described pass in described operation requests Key word is converted into the keyword storing with default random length structure, and further determines that in described operation requests whether wrap Containing the value corresponding with described keyword;Do not comprise described value in described operation requests in response to determining, then search with described The corresponding value being stored with default random length structure of the keyword that stored with default random length structure, afterwards Value being found, being stored with default random length structure is converted into the structure storage of default fixed length Value, and send the value after conversion to described user terminal.
In certain embodiments, methods described also includes:Described value is comprised in response to determining, then in described operation requests Described value is converted into the value storing with default random length structure, and determines that described operation requests are that data increases request Or data modification request, in response to determining that described operation requests are that data increases request, then with default non-described in storage The value of structure storage of fixed length and the described keyword being stored with default random length structure.
In certain embodiments, methods described also includes:In response to determining that described operation requests are data modification request, Then search with the described keyword identical keyword with default random length structure storage and with described keyword phase Corresponding value, and value corresponding for described and described keyword is revised as described storing with default random length structure Value.
In certain embodiments, the described key being converted into described keyword storing with default random length structure Word, including:Read described keyword, and obtain the keyword message of described keyword, wherein, described keyword message include with Descend at least one:Key length, the metadata of keyword;Described keyword message is filled up to default random length structure In body, to generate the keyword storing with default random length structure.
In certain embodiments, described value corresponding for described and described keyword is converted into default random length The value of structure storage, including:Read described value, and obtain the value information of described value, wherein, described value information include with down to One item missing:Value length, the metadata of value, expired time flag bit, least recently used time and quote number of times;By described value Information solicitation in default random length structure, to generate the value storing with default random length structure.
In certain embodiments, described by described with random length structure storage value be converted into default fixed length The value of structure storage, including:Read the described value with the storage of random length structure, and obtain described with random length structure Body storage value value information, wherein, described with random length structure storage value value information include following at least one: Value length, the metadata of value, expired time flag bit, least recently used time and quote number of times;By described with non-fixed length The value information of value of structure storage be filled up in the structure of default fixed length, to generate with the structure of default fixed length The value of storage.
Second aspect, this application provides a kind of device for sending data, described device includes:Determining unit, joins Put for the operation requests in response to receiving user terminal transmission, determine in described operation requests whether comprise keyword, its In, described keyword is with the keyword of the structure storage of default fixed length;Converting unit, is configured in response to determining Comprise keyword in described operation requests, then described keyword is converted into the key storing with default random length structure Word, and further determine that in described operation requests, whether to comprise the value corresponding with described keyword;Transmitting element, is configured to Do not comprise described value in described operation requests in response to determining, then search and stored with default random length structure with described The corresponding value being stored with default random length structure of keyword, afterwards by being found, with default non-fixed The value of long structure storage is converted into the value of the structure storage of default fixed length, and sends conversion to described user terminal Value afterwards.
In certain embodiments, described device also includes:Memory element, is configured in response to determining that described operation please Comprise described value in asking, then described value is converted into the value storing with default random length structure, and determines described operation Request is that data increases request or data modification request, in response to determining that described operation requests are that data increases request, then The described value with default random length structure storage of storage and the described key being stored with default random length structure Word.
In certain embodiments, described device also includes:Modification unit, is configured in response to determining that described operation please Seeking Truth data modification request, then search with the described keyword identical keyword being stored with default random length structure with And the value corresponding with described keyword, and by value corresponding for described and described keyword be revised as described with default non-fixed The value of long structure storage.
In certain embodiments, described converting unit includes:Acquisition module, is configured to read described keyword, and obtains Take the keyword message of described keyword, wherein, described keyword message include following at least one:Key length, crucial The metadata of word;Fill in module, be configured to described keyword message be filled up in default random length structure, with life Become the keyword storing with default random length structure.
In certain embodiments, described memory element includes:Acquisition module, is configured to read described value, and obtains institute State the value information of value, wherein, described value information include following at least one:Value length, the metadata of value, expired time mark Position, least recently used time and quote number of times;Fill in module, it is default non-fixed to be configured to be filled up to described value information In long structure, to generate the value storing with default random length structure.
In certain embodiments, described transmitting element includes:Acquisition module, is configured to described in reading with random length knot The value of structure body storage, and obtain the value information of the described value with the storage of random length structure, wherein, described with random length knot Structure body storage value value information include following at least one:Value length, the metadata of value, expired time flag bit, in the recent period Lack the time using and quote number of times;Fill in module, be configured to the value letter of the described value with the storage of random length structure Breath is filled up in the structure of default fixed length, to generate with the value of the structure storage of default fixed length.
The method and apparatus for sending data that the application provides, by determining in the operation requests that user terminal sends Whether comprise keyword and value corresponding with keyword however, it is determined that going out to comprise keyword, and do not comprise value corresponding with keyword When, then the key that will be converted into storing with default random length structure with the keyword of the structure storage of default fixed length Word, and search in key assignments type data base with the keyword of default random length structure storage corresponding with default The value of random length structure storage, afterwards, the value being stored with default random length structure is converted into default fixed The value of long structure storage, and send the value after conversion to user terminal, thus the adjustable length structure using compact Body data storage, can effectively lift memory usage.
Brief description
By reading the detailed description that non-limiting example is made made with reference to the following drawings, other of the application Feature, objects and advantages will become more apparent upon:
Fig. 1 is that the application can apply to exemplary system architecture figure therein;
Fig. 2 is the flow chart according to the application for sending an embodiment of the method for data;
Fig. 3 a is the flow chart according to the present embodiment for sending the data acquisition operations of the method for data;
Fig. 3 b is the flow chart increasing operation for the data sending the method for data according to the present embodiment;
Fig. 4 is the flow chart according to the application for sending another embodiment of the method for data;
Fig. 5 is for sending the structural representation of an embodiment of the device of data according to the application;
Fig. 6 is adapted for the structural representation of the computer system of the server for realizing the embodiment of the present application.
Specific embodiment
With reference to the accompanying drawings and examples the application is described in further detail.It is understood that this place is retouched The specific embodiment stated is used only for explaining related invention, rather than the restriction to this invention.It also should be noted that, in order to It is easy to describe, in accompanying drawing, illustrate only the part related to about invention.
It should be noted that in the case of not conflicting, the embodiment in the application and the feature in embodiment can phases Mutually combine.To describe the application below with reference to the accompanying drawings and in conjunction with the embodiments in detail.
Fig. 1 shows the method for sending data that can apply the application or the enforcement for sending the device of data The exemplary system architecture 100 of example.
As shown in figure 1, system architecture 100 can include terminal unit 101,102,103, network 104 server 105, 106.Network 104 is in order to provide the medium of communication link between terminal unit 101,102,103 server 105,106.Net Network 104 can include various connection types, for example wired, wireless communication link or fiber optic cables etc..
User 110 can be interacted with server 105,106 by network 104 with using terminal equipment 101,102,103, to connect Receive or send message etc..Various telecommunication customer end applications can be provided with terminal unit 101,102,103, such as shopping class should With, searching class application, web browser applications, JICQ, mailbox client, social platform software etc..
Terminal unit 101,102,103 can be had display screen and support that data receiver and the various electronics of transmission set Standby, including but not limited to smart mobile phone, panel computer, E-book reader, MP3 player (Moving Picture Experts Group Audio Layer III, dynamic image expert's compression standard audio frequency aspect 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image expert's compression standard audio frequency aspect 4) player, knee joint Mo(u)ld top half pocket computer and desk computer etc..
Server 105,106 can be the server providing various services, for example, send out on terminal unit 101,102,103 The operation requests sent provide the background server supported.Background server can be carried out to data such as the operation requests receiving point Analysis etc. is processed, and result (value corresponding with the keyword in operation requests for example finding) is fed back to terminal sets Standby.
It should be noted that the method for sending data that provided of the embodiment of the present application typically by server 105, 106 execution, correspondingly, the device for sending data is generally positioned in server 105,106.
It should be understood that the terminal unit in Fig. 1, the number of network server are only schematically.According to realizing need Will, can have any number of terminal unit, network server.
With continued reference to Fig. 2, show according to the application for sending the flow process of an embodiment of the method for data 200.The described method for sending data, comprises the following steps:
Step 201, in response to receiving the operation requests of user terminal transmission, determines in operation requests whether comprise key Word.
In the present embodiment, the method for sending data runs the electronic equipment (service described in such as Fig. 1 thereon Device) can by wired connection mode or radio connection from user utilize its to data (for example, keyword and with key The corresponding value of word) operation requests that the user terminal receive user that operated sends, wherein, described operation requests can be Data storage request or data increase request, can also be data modification request;Afterwards, above-mentioned electronic equipment is permissible Determine in aforesaid operations request and whether comprise keyword, wherein, above-mentioned keyword can be deposited with the structure of default fixed length The keyword of storage, above-mentioned keyword (Key, key) can be major key (Primary Key), can be in key assignments type data base One or more fields, the value (Value) corresponding with keyword is used for a certain in unique mark key assignments type data base Bar record.Structure is that have a same type or data acquisition system that different types of data is constituted by a series of, and structure can To be declared as variable, pointer or array etc., in order to realize more complicated data structure, structure is also some elements simultaneously Set, these elements are referred to as the member (member) of structure, and these members can typically use name for different types, member Word access.In actual items, the commonly used structure of research staff to form new type encapsulating some attributes it is therefore an objective to For simplified operation, allow user need not be concerned about the attribute of construction inner, structure etc., only need to be according to definition using just permissible ?.
Step 202, comprises keyword in response to determining in operation requests, then keyword is converted into default non-fixed The keyword of long structure storage, and further determine that in operation requests, whether to comprise the value corresponding with keyword.
In the present embodiment, after determining and comprising keyword in aforesaid operations request, above-mentioned electronic equipment can be In the accumulation layer of the bottom of key assignments type data base, Dram is adopted to arrange algorithm realizing above-mentioned with default fixed length The keyword of structure storage is converted into the keyword storing with default random length structure, no longer adopts the height of fixed length Spend structurized structure and carry out data storage, and adopt the structure data storage of the length dynamically changeable of compact, above-mentioned The storage organization of keyword and value corresponding with keyword can be separated by Dram arrangement algorithm, and afterwards, above-mentioned electronics sets Standby can determine in aforesaid operations request whether comprise the value corresponding with above-mentioned keyword.
In some optional implementations of the present embodiment, above-mentioned electronic equipment can read above-mentioned keyword first, And obtain the keyword message of above-mentioned keyword, wherein, above-mentioned keyword message can include key length it is also possible to include The metadata of keyword, can also include identifying the flag bit whether currently stored structure is " short length ", wherein, above-mentioned unit Data (Metadata) is also called broker data or relay data, for describing the data of data, is to data and information resources Descriptive information, the information of data attribute is mainly described, for supporting such as to indicate that storage location, historical data, resource are looked into Look for and the functions such as file record.Above-mentioned electronic equipment can judge to identify currently stored according to the key length getting The flag bit of " short length " of structure is 0 or 1, key length can be less than 128 bytes (byte) (i.e. 0 to 127 word Section) the flag bit of " short length " of keyword be set to 0;Key length is more than or equal to " the short length of the keyword of 128 bytes The flag bit of degree " is set to 1.Then, above-mentioned electronic equipment the above-mentioned keyword message getting can be filled up to default non- In the structure of fixed length, to generate the keyword storing with default random length structure.
As an example, when carrying out data storage under Redis data storage method, above-mentioned electronic equipment can be read first Take the keyword storing with robj memory element (the most basic memory element of redis object, primary Redis), and obtain The key length of above-mentioned keyword, when getting key length and being less than 128 byte, then currently deposits identifying in structure The structure of storage is that the flag bit of " short length " is set to 0, the key length getting is filled up in length field, and will close Key word is filled up in relief area, now, only keyword can be described using the description information of 1 byte with (i.e. flag bit accounts for With 1 bit (bit), length information occupancy 7 bits);When getting key length more than or equal to 128 byte, then by structure Identify the flag bit that currently stored structure is " short length " in body and be set to 1, before relief area, 4 bytes are used for representing crucial word length Degree, relief area the 5th byte points to keyword, and now, the description information using 5 bytes is described (i.e. flag bit to keyword Take 1 bit, length information takies 32 bits, separately have 7 bits to leave unused).
Step 203, does not comprise value in response to determining in operation requests, then search and with default random length structure The corresponding value being stored with default random length structure of the keyword of storage, afterwards by being found, with default The value of random length structure storage is converted into the value of the structure storage of default fixed length, and sends conversion to user terminal Value afterwards.
In the present embodiment, the keyword that above-mentioned electronic equipment can will be stored with default random length structure in advance With the corresponding relation of the value that with default random length structure stored corresponding with above-mentioned keyword is stored, wherein, Above-mentioned keyword is one-to-one with above-mentioned value.
In the present embodiment, when not comprising value in aforesaid operations request, above-mentioned electronic equipment can be in key assignments type data Corresponding being deposited with default random length structure of keyword searched in storehouse and stored with default random length structure The value of storage;Afterwards, value finding, being stored with default random length structure can be converted into default fixed length The value of structure storage, no longer adopts the structure data storage of the length dynamically changeable of compact, and adopts the height of fixed length Spend structurized structure and carry out data storage;Then, above-mentioned electronic equipment can send the value after conversion to user terminal.
In some optional implementations of the present embodiment, above-mentioned electronic equipment can read first above-mentioned with non-fixed length Structure storage value, and obtain above-mentioned with random length structure storage value value information, wherein, above-mentioned with non-fixed length Structure storage value value information can include following at least one:Value length, the metadata of value, expired time mark Position, least recently used time (LRU time), whether quote the structure of number of times (refcount) and the currently stored value of mark For the flag bit of " short length ", wherein, the above-mentioned least recently used time is in internal memory but no data block (internal memory Block) the least recently used time;Above-mentioned expired time flag bit is the flag bit identifying whether to carry expired time;Above-mentioned Metadata is also called broker data or relay data, for describing the data of data, is descriptive to data and information resources Information, mainly describes the information of data attribute, for supporting such as to indicate storage location, historical data, resource lookup and file The functions such as record.Afterwards, the value information of the above-mentioned value with the storage of random length structure can be filled up to by above-mentioned electronic equipment The structure of default fixed length is (for example in Redis data storage method, using redis object as the structure of memory element Body) in, to generate with the value of the structure storage of default fixed length.
With continued reference to Fig. 3 a and Fig. 3 b, Fig. 3 a is for sending the data acquisition behaviour of the method for data according to the present embodiment The flow chart made, Fig. 3 b is the flow chart increasing operation for the data sending the method for data according to the present embodiment.Former In raw Redis data storage method, data is with the structure of robj memory element storage, can will be calculated based on dynamic arrangement The data structure of the metadata of storage keyword value preset of method is named as magicKey and magicValue, hereinafter referred to as m.? In Fig. 3 a, comprise keyword when determining in the operation requests that user terminal sends, and when not comprising value corresponding with keyword, Then the keyword a301 being stored with robj memory element is converted into the keyword a302 of m memory element storage;Afterwards, in key Input in value type data base with the keyword a302 of m memory element storage, the key-value pair 303 obtaining exporting is:Keyword=pass Key word a, value=value a;Then, value a304 being stored with m memory element is converted into value a305 of robj memory element storage; Finally, send value a305 after conversion to user terminal.In fig 3b, when bag in the operation requests determining user terminal transmission Containing keyword, comprise value corresponding with keyword, and when operation requests increase request for data, then will be deposited with robj memory element The keyword a306 of storage is converted into the keyword a307 of m memory element storage, and the value that will be stored with robj memory element A308 is converted into value a309 of m memory element storage, then, by the keyword a307 being stored with m memory element with m storage Value a309 of unit storage stores in key assignments type data base, and the key-value pair 310 of increase is:Keyword=keyword a, value=value a.
With further reference to Fig. 4, it illustrates the flow process 400 of another embodiment of method for sending data.This use In the flow process 400 of the method sending data, comprise the following steps:
Step 401, in response to receiving the operation requests of user terminal transmission, determines in operation requests whether comprise key Word.
In the present embodiment, the method for sending data runs the electronic equipment (service described in such as Fig. 1 thereon Device) can be connect using the user terminal that it is operated to data from user by wired connection mode or radio connection Receive the operation requests that user sends, wherein, described operation requests can be data storage request or data increase please Ask, can also be data modification request;Afterwards, above-mentioned electronic equipment can determine in aforesaid operations request whether comprise key Word, wherein, structure is that have a same type or data acquisition system that different types of data is constituted by a series of, and structure can To be declared as variable, pointer or array etc., in order to realize more complicated data structure, structure is also some elements simultaneously Set, these elements are referred to as the member of structure, and these members can typically use name word access for different types, member.
Step 402, comprises keyword in response to determining in operation requests, then keyword is converted into default non-fixed The keyword of long structure storage, and further determine that in operation requests, whether to comprise the value corresponding with keyword.
In the present embodiment, after determining and comprising keyword in aforesaid operations request, above-mentioned electronic equipment can be In the accumulation layer of the bottom of key assignments type data base, Dram is adopted to arrange algorithm realizing above-mentioned with default fixed length The keyword of structure storage is converted into the keyword storing with default random length structure, no longer adopts the height of fixed length Spend structurized structure and carry out data storage, and adopt the structure data storage of the length dynamically changeable of compact, above-mentioned The storage organization of keyword and value corresponding with keyword can be separated by Dram arrangement algorithm, and afterwards, above-mentioned electronics sets Standby can determine in aforesaid operations request whether comprise the value corresponding with above-mentioned keyword, if comprise in aforesaid operations request with The corresponding value of above-mentioned keyword, then execution step 404;If not comprising corresponding with above-mentioned keyword in aforesaid operations request Value, then execution step 403.
Step 403, does not comprise value in response to determining in operation requests, then search and with default random length structure The corresponding value being stored with default random length structure of the keyword of storage, afterwards by being found, with default The value of random length structure storage is converted into the value of the structure storage of default fixed length, and sends conversion to user terminal Value afterwards.
In the present embodiment, when not comprising value in aforesaid operations request, above-mentioned electronic equipment can be in key assignments type data Corresponding being deposited with default random length structure of keyword searched in storehouse and stored with default random length structure The value of storage;Afterwards, value finding, being stored with default random length structure can be converted into default fixed length The value of structure storage, no longer adopts the structure data storage of the length dynamically changeable of compact, and adopts the height of fixed length Spend structurized structure and carry out data storage;Then, above-mentioned electronic equipment can send the value after conversion to user terminal.
Step 404, comprises value in response to determining in operation requests, then value is converted into default random length structure The value of body storage.
In the present embodiment, when determine aforesaid operations request in comprise value after, above-mentioned electronic equipment can be in key assignments In the accumulation layer of type data base, Dram arrangement algorithm is adopted to realize turning the value of the structure storage with default fixed length Change the value storing with default random length structure into, no longer data is carried out using the structure of the highly structural of fixed length Storage, and adopt the structure data storage of the length dynamically changeable of compact.
In some optional implementations of the present embodiment, above-mentioned electronic equipment can read above-mentioned and keyword first Corresponding value, and obtain the value information of above-mentioned value, wherein, above-mentioned value information can include following at least one:Value length, value Metadata, expired time flag bit, least recently used time, quote number of times and the structure of the currently stored value of mark is The no flag bit for " short length ", wherein, the above-mentioned least recently used time is in internal memory but no data block The least recently used time;Above-mentioned expired time flag bit is the flag bit identifying whether to carry expired time;Above-mentioned unit number According to being also called broker data or relay data, for describing the data of data, it is the descriptive information to data and information resources, The information of data attribute is mainly described, for supporting such as to indicate storage location, historical data, resource lookup and file record etc. Function.Above-mentioned electronic equipment can judge to identify the structure of currently stored value as " short length " according to the value length getting Flag bit be 0 or 1, the flag bit of " short length " of the value that value length can be less than 256 bytes be set to 0;Length will be worth It is set to 1 more than or equal to the flag bit of " short length " of the value of 256 bytes.Above-mentioned electronic equipment can also be according to the data getting In whether carry expired time come to arrange mark expired time flag bit be 0 or 1, if get not carrying expired time, Then expired time flag bit is set to 0;If get carrying expired time, expired time flag bit is set to 1.It Afterwards, above-mentioned value information can be filled up in above-mentioned default random length structure for above-mentioned electronic equipment, to generate with default The storage of random length structure value.
As an example, when carrying out data storage under Redis data storage method, above-mentioned electronic equipment can be read first Take with the value of robj memory element storage, and obtain in above-mentioned value whether carry expired time, if not carrying expired time, will Expired time flag bit is set to 0, then obtains the value length of above-mentioned value, when getting value length and being less than 256 byte, then will tie Identify the flag bit that currently stored structure is " short length " in structure body and be set to 0, the 1st byte representation length of relief area, delay Rush the 2nd byte sensing value in area, now, the description information using 5 bytes can be described (i.e. " short length " flag bit to value Take 1 bit, expired time mark bit occupancy 1 bit, quote number of times and take 6 bits, the LRU time takies 24 bits, length is believed Breath takies 8 bits);When the value length getting is more than or equal to 256 byte, then will identify currently stored structure in structure Flag bit for " short length " is set to 1, and before relief area, 4 bytes are used for representing value length, relief area the 5th byte sensing value, this When, the description information using 8 bytes can be described (i.e. " short length " mark bit occupancy 1 bit, expired time mark to value Bit occupancy 1 bit, quotes number of times and takies 6 bits, the LRU time takies 24 bits, length information takies 32 bits).If carrying Time phase, then expired time flag bit is set to 1, front 4 byte representation expired time information of relief area, then the storage being worth POS INT point 4 bytes of corresponding skew.
In the present embodiment, when carrying out data storage under Redis data storage method, when storage is key length During the key-value pair of the String type being less than 256 bytes less than 128 bytes, value length, carried out using Dram arrangement algorithm Storage only needs the EMS memory occupation of the descriptive information of 6 bytes, and the primary data storage side based on robj memory element of Redis Formula needs the memory headroom of 56 bytes that data is stored.When the key carrying out String type using Dram arrangement algorithm , to during storage, key length value preset length is less, and the memory headroom of saving is bigger for value.
Step 405, determines that operation requests are that data increases request or data modification request.
In the present embodiment, above-mentioned electronic equipment can determine that aforesaid operations request is that data increases request or data is repaiied Change request, be by keyword and/or value storage in key assignments type data base or by key assignments type data base with user terminal The corresponding value of keyword in the operation requests sending is modified as the value in the operation requests of user terminal transmission.
Step 406, in response to determining that operation requests are that data increases request, then stores with default random length structure The value of body storage and the keyword being stored with default random length structure.
In the present embodiment, it is that data increases request when determining aforesaid operations request, then above-mentioned electronic equipment can be by The above-mentioned value with default random length structure storage and the keyword being stored with default random length structure are stored In key assignments type data base.
Step 407, in response to determining that operation requests are data modification request, then searches and with default random length knot The keyword identical keyword of structure body storage and the value corresponding with keyword, and the value corresponding with keyword is changed It is the value being stored with default random length structure.
In the present embodiment, when determining that aforesaid operations request is data modification request, then above-mentioned electronic equipment can be first First search in key assignments type data base with the above-mentioned keyword identical keyword being stored with default random length structure and The value of storage in the above-mentioned type data base in key assignments afterwards, can be revised as above-mentioned user terminal by the corresponding value to this keyword The value being stored with default random length structure after conversion in the operation requests sending.
Figure 4, it is seen that the method for sending data compared with embodiment corresponding with Fig. 2, in the present embodiment Flow process 400 highlight in key assignments type data base increase data step and in key assignments type data base change data step Suddenly.Thus, the scheme of the present embodiment description can also adopt the adjustable length structure data storage of compact, thus more entering One step improve memory usage.
With further reference to Fig. 5, as the realization to method shown in above-mentioned each figure, this application provides one kind is used for sending number According to device an embodiment, this device embodiment is corresponding with the embodiment of the method shown in Fig. 2, and this device specifically can be answered For in various electronic equipments.
As shown in figure 5, the device 500 for sending data described in the present embodiment includes:Determining unit 501, conversion are single Unit 502 and transmitting element 503.Wherein it is determined that the operation that unit 501 is configured in response to receiving user terminal transmission please Ask, determine in described operation requests, whether to comprise keyword, wherein, described keyword is the structure storage with default fixed length Keyword;Converting unit 502 is configured to comprise keyword in described operation requests in response to determining, then by described key Word is converted into the keyword storing with default random length structure, and further determines that in described operation requests whether comprise The value corresponding with described keyword;Transmitting element 503 is configured to not comprise institute in described operation requests in response to determining State value, then search corresponding with the described keyword with default random length structure storage with default random length knot The value of structure body storage, afterwards value being found, being stored with default random length structure is converted into default fixed The value of long structure storage, and send the value after conversion to described user terminal.
In the present embodiment, for sending determining unit 501, converting unit 502 and the transmitting element of the device 500 of data 503 concrete process and its technique effect that brought can respectively with reference to step 201 in the corresponding embodiment of Fig. 2, step 202 and The related description of the implementation of step 203, will not be described here.
In some optional implementations of the present embodiment, the above-mentioned device 500 for sending data can also include Memory element 504.When determine aforesaid operations request in comprise value after, said memory cells 504 can be in key assignments type data In the accumulation layer of the bottom in storehouse, Dram arrangement algorithm is adopted to realize the value that will store with the structure of default fixed length It is converted into the value storing with default random length structure, no longer line number is entered using the structure of the highly structural of fixed length According to storage, and adopt the structure data storage of the length dynamically changeable of compact;Afterwards it may be determined that aforesaid operations request is Data increases request or data modification request, is to store in key assignments type data base keyword and/or value still by key In value type data base, the value corresponding with the keyword in the operation requests that user terminal sends is modified as user terminal transmission Value in operation requests;When determining that aforesaid operations request is that data increases request, then said memory cells 504 can will be above-mentioned The value being stored with default random length structure and the keyword being stored with default random length structure store key assignments In type data base.
In some optional implementations of the present embodiment, the above-mentioned device 500 for sending data can also include Modification unit 505.When determining that aforesaid operations request is data modification request, then above-mentioned modification unit 505 can be first in key Search in value type data base and the above-mentioned keyword identical keyword being stored with default random length structure and to this pass The value of storage in the above-mentioned type data base in key assignments afterwards, can be revised as what above-mentioned user terminal sent by the corresponding value of key word The value being stored with default random length structure after conversion in operation requests.
In some optional implementations of the present embodiment, above-mentioned converting unit 502 can include acquisition module 5021 With fill in module 5022.Above-mentioned acquisition module 5021 can read above-mentioned keyword first, and obtains the key of above-mentioned keyword Word information, wherein, above-mentioned keyword message can include key length it is also possible to include the metadata of keyword, acceptable Including identifying the flag bit whether currently stored structure is " short length ".Above-mentioned acquisition module 5021 can be according to getting Key length, can be by key length judging that the flag bit of " short length " that identify currently stored structure is 0 or 1 It is set to 0 less than the flag bit of " short length " of the keyword of 128 bytes;Key length is more than or equal to the key of 128 bytes The flag bit of " short length " of word is set to 1.Then, the above-mentioned keyword message getting can be filled out by above-mentioned module 5022 of filling in Write in default random length structure, to generate the keyword storing with default random length structure.
In some optional implementations of the present embodiment, said memory cells 504 can include acquisition module 5041 With fill in module 5042.Above-mentioned acquisition module 5041 can read the above-mentioned value corresponding with keyword first, and obtains above-mentioned Value value information, wherein, above-mentioned value information can include following at least one:Value length, the metadata of value, expired time mark Position, the least recently used time, quote number of times and the currently stored value of mark structure be whether " short length " flag bit. Above-mentioned acquisition module 5041 can judge to identify the structure of currently stored value as " short length " according to the value length getting Flag bit be 0 or 1, the flag bit of " short length " of the value that value length can be less than 256 bytes be set to 0;Length will be worth It is set to 1 more than or equal to the flag bit of " short length " of the value of 256 bytes.Above-mentioned acquisition module 5041 can also be according to getting Expired time whether is carried to arrange the flag bit of mark expired time be 0 or 1, if getting when not carrying expired in data Between, then expired time flag bit is set to 0;If get carrying expired time, expired time flag bit is set to 1. Afterwards, above-mentioned value information can be filled up in above-mentioned default random length structure for above-mentioned module 5042 of filling in, to generate The value being stored with default random length structure.
In some optional implementations of the present embodiment, above-mentioned transmitting element 503 can include acquisition module 5031 With fill in module 5032.Above-mentioned acquisition module 5031 can read the above-mentioned value with the storage of random length structure first, and obtains Take the value information of the above-mentioned value with the storage of random length structure, wherein, the value of the above-mentioned value with the storage of random length structure Information can include following at least one:Value length, value metadata, expired time flag bit, the least recently used time, Whether the structure quoting number of times and the currently stored value of mark is the flag bit of " short length ".Afterwards, above-mentioned fill in module 5032 The structure that the value information of the above-mentioned value with the storage of random length structure can be filled up to default fixed length (for example exists In Redis data storage method, using redis object as the structure of memory element) in, to generate with default fixed length Structure storage value.
Below with reference to Fig. 6, it illustrates the computer system 600 being suitable to the server for realizing the embodiment of the present invention Structural representation.
As shown in fig. 6, computer system 600 includes CPU (CPU) 601, it can be read-only according to being stored in Program in memorizer (ROM) 602 or be loaded into program random access storage device (RAM) 603 from storage part 608 and Execute various suitable actions and process.In RAM603, the system that is also stored with 600 operates required various program datas. CPU601, ROM602 and RAM603 are connected with each other by bus 604.Input/output (I/O) interface 605 is also connected to bus 604.
Connected to I/O interface 605 with lower component:Importation 606 including keyboard, mouse etc.;Penetrate including such as negative electrode Spool (CRT), liquid crystal display (LCD) etc. and the output par, c 607 of speaker etc.;Storage part 608 including hard disk etc.; And include the communications portion 609 of the NIC of LAN card, modem etc..Communications portion 609 via such as because The network execution communication process of special net.Driver 610 connects to I/O interface 605 also according to needs.Detachable media 611, such as Disk, CD, magneto-optic disk, semiconductor memory etc., are arranged in driver 610, as needed in order to read from it Computer program as needed be mounted into storage part 608.
Especially, in accordance with an embodiment of the present disclosure, the process above with reference to flow chart description may be implemented as computer Software program.For example, embodiment of the disclosure includes a kind of computer program, and it includes being tangibly embodied in machine readable Computer program on medium, above computer program bag contains the program code for the method shown in execution flow chart.At this In the embodiment of sample, this computer program can be downloaded and installed from network by communications portion 609, and/or from removable Unload medium 611 to be mounted.
Flow chart in accompanying drawing and block diagram are it is illustrated that according to the system of various embodiments of the invention, method and computer journey The architectural framework in the cards of sequence product, function and operation.At this point, each square frame in flow chart or block diagram can generation A part for one module of table, program segment or code, the part of above-mentioned module, program segment or code comprises one or more For realizing the executable instruction of the logic function of regulation.It should also be noted that in some realizations as replacement, institute in square frame The function of mark can also be to occur different from the order being marked in accompanying drawing.For example, the square frame that two succeedingly represent is actual On can execute substantially in parallel, they can also execute sometimes in the opposite order, and this is depending on involved function.Also to It is noted that the combination of each square frame in block diagram and/or flow chart and the square frame in block diagram and/or flow chart, Ke Yiyong Execute the function of regulation or the special hardware based system of operation to realize, or can be referred to computer with specialized hardware The combination of order is realizing.
It is described in involved unit in the embodiment of the present invention to realize by way of software it is also possible to pass through hard The mode of part is realizing.Described unit can also be arranged within a processor, for example, it is possible to be described as:A kind of processor bag Include determining unit, converting unit and transmitting element.Wherein, the title of these units is not constituted under certain conditions to this unit The restriction of itself.For example, determining unit is also described as " in response to receiving the operation requests of user terminal transmission, really The unit of keyword whether is comprised " in fixed described operation requests.
As another aspect, present invention also offers a kind of nonvolatile computer storage media, this non-volatile calculating Machine storage medium can be the nonvolatile computer storage media included in said apparatus in above-described embodiment;Can also be Individualism, without the nonvolatile computer storage media allocated in terminal.Above-mentioned nonvolatile computer storage media is deposited Contain one or more program, when said one or multiple program are executed by an equipment so that the said equipment:Response In the operation requests receiving user terminal transmission, determine in described operation requests, whether to comprise keyword, wherein, described key Word is with the keyword of the structure storage of default fixed length;Comprise keyword in response to determining in described operation requests, then Described keyword is converted into the keyword storing with default random length structure, and further determines that described operation requests In whether comprise the value corresponding with described keyword;Do not comprise described value in response to determining in described operation requests, then look into Look for and described corresponding being stored with default random length structure of keyword being stored with default random length structure Value, afterwards value being found, being stored with default random length structure is converted into the structure of default fixed length The value of body storage, and send the value after conversion to described user terminal.
Above description is only presently preferred embodiments of the present invention and the explanation to institute's application technology principle.People in the art Member is it should be appreciated that involved invention scope is however it is not limited to the technology of the particular combination of above-mentioned technical characteristic in the present invention Scheme, also should cover simultaneously in the case of without departing from described inventive concept, be carried out by above-mentioned technical characteristic or its equivalent feature Combination in any and other technical schemes of being formed.Such as features described above has similar work(with the (but not limited to) disclosed in the present invention The technical scheme that the technical characteristic of energy is replaced mutually and formed.

Claims (12)

1. a kind of method for sending data is it is characterised in that methods described includes:
In response to receiving the operation requests of user terminal transmission, determine in described operation requests, whether to comprise keyword, wherein, Described keyword is with the keyword of the structure storage of default fixed length;
Comprise keyword in described operation requests in response to determining, then described keyword is converted into default random length The keyword of structure storage, and further determine that in described operation requests, whether to comprise the value corresponding with described keyword;
Do not comprise described value in described operation requests in response to determining, then search with described with default random length structure The corresponding value being stored with default random length structure of the keyword of storage, afterwards by being found, with default The value of random length structure storage is converted into the value of the structure storage of default fixed length, and sends to described user terminal Value after conversion.
2. method according to claim 1 is it is characterised in that methods described also includes:
Comprise described value in described operation requests in response to determining, then described value is converted into default random length structure The value of body storage, and determine that described operation requests are that data increases request or data modification request, described in response to determining Operation requests are that data increases request, then store the described value storing with default random length structure and described with default The keyword of random length structure storage.
3. method according to claim 2 is it is characterised in that methods described also includes:
In response to determining that described operation requests are data modification request, then search with described with default random length structure The keyword identical keyword of storage and the value corresponding with described keyword, and will be corresponding for described and described keyword Value be revised as the described value storing with default random length structure.
4. method according to claim 1 is it is characterised in that described described keyword is converted into default non-fixed length Structure storage keyword, including:
Read described keyword, and obtain the keyword message of described keyword, wherein, described keyword message include with down to One item missing:Key length, the metadata of keyword;
Described keyword message is filled up in default random length structure, to generate with default random length structure The keyword of storage.
5. method according to claim 2 is it is characterised in that described change value corresponding for described and described keyword Become the value storing with default random length structure, including:
Read described value, and obtain the value information of described value, wherein, described value information include following at least one:Value length, value Metadata, expired time flag bit, least recently used time and quote number of times;
Described value information is filled up in default random length structure, is stored with default random length structure with generating Value.
6. method according to claim 1 is it is characterised in that described turn the described value with the storage of random length structure Change the value storing with the structure of default fixed length into, including:
Read the described value with the storage of random length structure, and obtain the value letter of the described value with the storage of random length structure Breath, wherein, described with random length structure storage value value information include following at least one:Value length, first number of value According to, expired time flag bit, least recently used time and quote number of times;
The described value information of value with the storage of random length structure is filled up in the structure of default fixed length, with generate with The value of the structure storage of default fixed length.
7. a kind of device for sending data is it is characterised in that described device includes:
Determining unit, is configured to the operation requests in response to receiving user terminal transmission, determining in described operation requests is No comprise keyword, wherein, described keyword is with the keyword of the structure of default fixed length storage;
Converting unit, is configured to comprise keyword in described operation requests in response to determining, then change described keyword Become the keyword storing with default random length structure, and further determine that whether comprise in described operation requests with described The corresponding value of keyword;
Transmitting element, is configured to not comprise described value in described operation requests in response to determining, then search with described with pre- If the storage of random length structure the corresponding value being stored with default random length structure of keyword, afterwards by institute Value finding, being stored with default random length structure is converted into the value of the structure storage of default fixed length, and Send the value after conversion to described user terminal.
8. device according to claim 7 is it is characterised in that described device also includes:
Memory element, is configured to comprise described value in described operation requests in response to determining, then by described value be converted into The value of default random length structure storage, and determine that described operation requests are that data increases request or data modification please Ask, in response to determining that described operation requests are that data increases request, then deposited with default random length structure described in storage The value of storage and the described keyword being stored with default random length structure.
9. device according to claim 8 is it is characterised in that described device also includes:
Modification unit, is configured in response to determining that described operation requests are data modification request, then search with described with pre- If the keyword identical keyword of random length structure storage and the value corresponding with described keyword, and will be described The value corresponding with described keyword is revised as the described value storing with default random length structure.
10. device according to claim 7 is it is characterised in that described converting unit includes:
Acquisition module, is configured to read described keyword, and obtains the keyword message of described keyword, wherein, described pass Key word information include following at least one:Key length, the metadata of keyword;
Fill in module, be configured to described keyword message is filled up in default random length structure, to generate with pre- If the storage of random length structure keyword.
11. devices according to claim 8 are it is characterised in that described memory element includes:
Acquisition module, is configured to read described value, and obtains the value information of described value, and wherein, described value information includes following At least one:Value length, the metadata of value, expired time flag bit, least recently used time and quote number of times;
Fill in module, be configured to described value information is filled up in default random length structure, to generate with default The value of random length structure storage.
12. devices according to claim 7 are it is characterised in that described transmitting element includes:
Acquisition module, is configured to read the described value with the storage of random length structure, and obtain described with random length knot The value information of the value of structure body storage, wherein, the value information of the described value with the storage of random length structure includes following at least one ?:Value length, the metadata of value, expired time flag bit, least recently used time and quote number of times;
Fill in module, be configured to for the value information of the described value with the storage of random length structure to be filled up to default fixed length In structure, to generate with the value of the structure storage of default fixed length.
CN201610917492.XA 2016-10-20 2016-10-20 Method and apparatus for sending data Active CN106446272B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610917492.XA CN106446272B (en) 2016-10-20 2016-10-20 Method and apparatus for sending data

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610917492.XA CN106446272B (en) 2016-10-20 2016-10-20 Method and apparatus for sending data

Publications (2)

Publication Number Publication Date
CN106446272A true CN106446272A (en) 2017-02-22
CN106446272B CN106446272B (en) 2019-07-09

Family

ID=58176450

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610917492.XA Active CN106446272B (en) 2016-10-20 2016-10-20 Method and apparatus for sending data

Country Status (1)

Country Link
CN (1) CN106446272B (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107741833A (en) * 2017-10-30 2018-02-27 广东乐心医疗电子股份有限公司 Storage method and device of nestable key-value
CN108388598A (en) * 2018-02-01 2018-08-10 平安科技(深圳)有限公司 Electronic device, date storage method and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1455557A (en) * 2002-03-25 2003-11-12 联合特里西斯株式会社 Changeable length/fixed length data conversion method and apparatus
US20050223022A1 (en) * 2004-04-02 2005-10-06 Salesforce.Com, Inc. Custom entities and fields in a multi-tenant database system
WO2010129063A1 (en) * 2009-05-08 2010-11-11 Alibaba Group Holding Limited Method and system for search engine indexing and searching using the index
CN103106158A (en) * 2011-08-08 2013-05-15 株式会社东芝 Memory system including key-value store
CN103389992A (en) * 2012-05-09 2013-11-13 北京百度网讯科技有限公司 Structured data storage method and device
CN105373541A (en) * 2014-08-22 2016-03-02 博雅网络游戏开发(深圳)有限公司 Processing method and system for data operation request of database

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1455557A (en) * 2002-03-25 2003-11-12 联合特里西斯株式会社 Changeable length/fixed length data conversion method and apparatus
US20050223022A1 (en) * 2004-04-02 2005-10-06 Salesforce.Com, Inc. Custom entities and fields in a multi-tenant database system
WO2010129063A1 (en) * 2009-05-08 2010-11-11 Alibaba Group Holding Limited Method and system for search engine indexing and searching using the index
CN103106158A (en) * 2011-08-08 2013-05-15 株式会社东芝 Memory system including key-value store
CN103389992A (en) * 2012-05-09 2013-11-13 北京百度网讯科技有限公司 Structured data storage method and device
CN105373541A (en) * 2014-08-22 2016-03-02 博雅网络游戏开发(深圳)有限公司 Processing method and system for data operation request of database

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107741833A (en) * 2017-10-30 2018-02-27 广东乐心医疗电子股份有限公司 Storage method and device of nestable key-value
CN108388598A (en) * 2018-02-01 2018-08-10 平安科技(深圳)有限公司 Electronic device, date storage method and storage medium
WO2019148720A1 (en) * 2018-02-01 2019-08-08 平安科技(深圳)有限公司 Electronic device, data storage method and storage medium
CN108388598B (en) * 2018-02-01 2022-04-22 平安科技(深圳)有限公司 Electronic device, data storage method, and storage medium

Also Published As

Publication number Publication date
CN106446272B (en) 2019-07-09

Similar Documents

Publication Publication Date Title
CN105631035B (en) Date storage method and device
TWI682335B (en) Data object display method and device
CN106886568B (en) One kind divides table method, apparatus and electronic equipment
CN106407303A (en) Data storage method and apparatus, and data query method and apparatus
CN105681477B (en) A kind of data access method and a kind of server
CN106708996A (en) Method and system for full text search of relational database
CN103812888A (en) Information pushing, receiving and transmitting method, server, client and system
CN107229718A (en) The method and apparatus for handling report data
EP2778968B1 (en) Mobile telecommunication device remote access to cloud-based or virtualized database systems
US20190095500A1 (en) Statistical processing of natural language queries of data sets
US20080249994A1 (en) System and process for server side stateless data interchange
CN103970758A (en) Database accessing system and method
CN103455555B (en) Recommendation method and recommendation apparatus based on mobile terminal similarity
CN104657435A (en) Storage management method for application data and network management system
CN111950857A (en) Index system management method and device based on service indexes and electronic equipment
US11157467B2 (en) Reducing response time for queries directed to domain-specific knowledge graph using property graph schema optimization
CN107844488A (en) Data query method and apparatus
CN106446272A (en) Method and device for sending data
CN105404974A (en) Data capitalization method and apparatus and management platform
CN112650804B (en) Big data access method, device, system and storage medium
CN110297945B (en) Data information processing method and system based on XBRL
CN105404672A (en) Webpage data storage and operation system and method
CN113626223A (en) Interface calling method and device
CN109255082A (en) Bookmark display methods and device
CN107729394A (en) Data Mart management system and its application method based on Hadoop clusters

Legal Events

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