CN106446272B - Method and apparatus for sending data - Google Patents

Method and apparatus for sending data Download PDF

Info

Publication number
CN106446272B
CN106446272B CN201610917492.XA CN201610917492A CN106446272B CN 106446272 B CN106446272 B CN 106446272B CN 201610917492 A CN201610917492 A CN 201610917492A CN 106446272 B CN106446272 B CN 106446272B
Authority
CN
China
Prior art keywords
value
keyword
structural body
storage
preset
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201610917492.XA
Other languages
Chinese (zh)
Other versions
CN106446272A (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

Abstract

This application discloses the method and apparatus for sending data.Whether one specific embodiment of the method includes: the operation requests in response to receiving user terminal transmission, determine in operation requests comprising keyword, wherein keyword is the keyword stored with the structural body of preset fixed length;In response to determining comprising keyword in operation requests, then keyword is converted into the keyword of preset random length structural body storage, and whether further determine that in operation requests comprising value corresponding with keyword;In response to determining not including value in operation requests, then search the value with preset random length structural body storage corresponding with the keyword stored with preset random length structural body, later by it is being found, the value stored with the structural body of preset fixed length is converted into the value of preset random length structural body storage, and send the value after conversion to user terminal.The embodiment effectively improves memory usage.

Description

Method and apparatus for sending data
Technical field
This application involves field of computer technology, and in particular to technical field of data processing, more particularly, to transmission number According to method and apparatus.
Background technique
Key assignments type (Key-Value) storing data library (for example, Redis storing data library) with its high-performance, is supported to enrich Data structure the features such as, a large amount of market part is already taken up in NoSQL (Not Only SQL, non-relational database) Volume.When the data of key assignments type database are stored entirely in memory, program itself is being to support more data structures System design level, in order to which versatility has done the compromise on many memory headrooms.And many business are during use, only make With the storage (i.e. Key-Value storage) of simple String type, under this application scenarios, it will result in key assignments type data There is excessive descriptive data structure committed memory in library, 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, to waste a large amount of of server Memory source.
The existing mode for improving memory usage be usually key-value pair is packaged into Hash function at business end, but this Kind mode requires business side to modify service code, opaque to the user of key assignments type database.
Summary 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 issues of technology segment is mentioned.
In a first aspect, this application provides a kind of methods for sending data, which comprises in response to receiving Whether the operation requests that user terminal is sent determine in the operation requests comprising keyword, wherein the keyword is with pre- If fixed length structural body storage keyword;In response to determining comprising keyword in the operation requests, then by the pass Whether key word is converted into the keyword of preset random length structural body storage, and further determine that in the operation requests and wrap Containing value corresponding with the keyword;In response to determine in the operation requests do not include described value, then search with it is described With the corresponding value with preset random length structural body storage of the keyword of preset random length structural body storage, later By it is being found, with the value of preset random length structural body storage be converted into storing with the structural body of preset fixed length Value, and the value after conversion is sent to the user terminal.
In some embodiments, the method also includes: in response to determining in the operation requests comprising described value, then Described value is converted into the value of preset random length structural body storage, and determines that the operation requests are that data increase request Or data modification request, in response to determining that the operation requests are that data increase request, then storage is described with preset non- The value of the structural body storage of fixed length and the keyword with preset random length structural body storage.
In some embodiments, the method also includes: in response to determining that the operation requests are data modification requests, Then search with the identical keyword of keyword stored with preset random length structural body and with the keyword phase Corresponding value, and the value corresponding with the keyword is revised as described with preset random length structural body storage Value.
In some embodiments, described that the keyword is converted into the key of preset random length structural body storage Word, comprising: read the keyword, and obtain the keyword message of the keyword, wherein the keyword message include with It is at least one of lower: key length, the metadata of keyword;The keyword message is filled up to preset random length structure In body, to generate with the keyword of preset random length structural body storage.
In some embodiments, described that the value corresponding with the keyword is converted into preset random length The value of structural body storage, comprising: read described value, and obtain the value information of described value, wherein described value information includes below extremely One item missing: value length, the metadata of value, expired time flag bit, least recently used time and reference number;By described value Information solicitation is into preset random length structural body, to generate with the value of preset random length structural body storage.
In some embodiments, described that the value with the storage of random length structural body is converted into preset fixed length The value of structural body storage, comprising: read the value stored with random length structural body, and obtain described with random length structure The value information of the value of body storage, wherein the value information of the value with the storage of random length structural body includes at least one of the following: It is worth length, the metadata of value, expired time flag bit, least recently used time and reference number;It will be described with non-fixed length The value information of value of structural body storage be filled up in the structural body of preset fixed length, to generate with the structural body of preset fixed length The value of storage.
Second aspect, this application provides a kind of for sending the device of data, and described device comprises determining that unit, matches It sets for the operation requests in response to receiving user terminal transmission, determines in the operation requests whether include keyword, In, the keyword is the keyword stored with the structural body of preset fixed length;Converting unit is configured in response to determining Include keyword in the operation requests, then the keyword is converted into the key of preset random length structural body storage Word, and whether further determine that in the operation requests comprising value corresponding with the keyword;Transmission unit is configured to In response to determining not including described value in the operation requests, then searches and stored with described with preset random length structural body The corresponding value with preset random length structural body storage of keyword, later by it is being found, with preset non-fixed The value of long structural body storage is converted into the value stored with the structural body of preset fixed length, and sends and convert to the user terminal Value afterwards.
In some embodiments, described device further include: storage unit is configured in response to determining that the operation is asked Include described value in asking, then described value is converted into the value of preset random length structural body storage, and determine the operation Request is that data increase request or data modification request, in response to determining that the operation requests are that data increase request, then Storage is described with the value of preset random length structural body storage and the key with preset random length structural body storage Word.
In some embodiments, described device further include: modification unit is configured in response to determining that the operation is asked Seeking Truth data modification request, then search keyword identical with the keyword stored with preset random length structural body with And value corresponding with the keyword, and the value corresponding with the keyword is revised as described with preset non-fixed The value of long structural body storage.
In some embodiments, the converting unit includes: acquisition module, is configured to read the keyword, and obtain Take the keyword message of the keyword, wherein the keyword message includes at least one of the following: key length, crucial The metadata of word;Module is filled in, is configured to for the keyword message being filled up in preset random length structural body, with life At with the keyword of preset random length structural body storage.
In some embodiments, the storage unit includes: acquisition module, is configured to read described value, and obtain institute State the value information of value, wherein described value information includes at least one of the following: value length, the metadata of value, expired time mark Position, least recently used time and reference number;Module is filled in, is configured to described value information solicitation to preset non-fixed In long structural body, to generate with the value of preset random length structural body storage.
In some embodiments, the transmission unit includes: acquisition module, is configured to read described with random length knot The value of structure body storage, and obtain the value information of the value with the storage of random length structural body, wherein it is described with random length knot The value information of the value of structure body storage include at least one of the following: value length, the metadata of value, expired time flag bit, it is recent most The time used less and reference number;Module is filled in, is configured to the value letter of the value with the storage of random length structural body Breath is filled up in the structural body of preset fixed length, to generate with the value of the structural body storage of preset fixed length.
Method and apparatus provided by the present application for sending data, by determine user terminal send operation requests in It whether include keyword and value corresponding with keyword, however, it is determined that out include keyword, and do not include value corresponding with keyword When, then the keyword stored with the structural body of preset fixed length is converted into the key of preset random length structural body storage Word, and lookup is corresponding with preset with the keyword of preset random length structural body storage in key assignments type database The value of random length structural body storage will be converted into later with the value of preset random length structural body storage with preset fixed The value of long structural body storage, and the value after conversion is sent to user terminal, thus the structure variable using the length of compact Body storing data can effectively promote memory usage.
Detailed description of the invention
By reading a detailed description of non-restrictive embodiments in the light of the attached drawings below, the application's is other Feature, objects and advantages will become more apparent upon:
Fig. 1 is that this application can be applied to exemplary system architecture figures therein;
Fig. 2 is the flow chart according to one embodiment of the method for sending data of the application;
Fig. 3 a is the flow chart according to the data acquisition operations of the method for sending data of the present embodiment;
Fig. 3 b is the flow chart for increasing operation according to the data of the method for sending data of the present embodiment;
Fig. 4 is the flow chart according to another embodiment of the method for sending data of the application;
Fig. 5 is the structural schematic diagram according to one embodiment of the device for sending data of the application;
Fig. 6 is adapted for the structural schematic diagram for the computer system for realizing the server of the embodiment of the present application.
Specific embodiment
The application is described in further detail with reference to the accompanying drawings and examples.It is understood that this place is retouched The specific embodiment stated is used only for explaining related invention, rather than the restriction to the invention.It also should be noted that in order to Convenient for description, part relevant to related invention is illustrated only in attached drawing.
It should be noted that in the absence of conflict, the features in the embodiments and the embodiments of the present application can phase Mutually combination.The application is described in detail below with reference to the accompanying drawings and in conjunction with the embodiments.
Fig. 1 is shown can be using the method for sending data of the application or the implementation of the device for sending data The exemplary system architecture 100 of example.
As shown in Figure 1, system architecture 100 may include terminal device 101,102,103, network 104 and server 105, 106.Network 104 between terminal device 101,102,103 and server 105,106 to provide the medium of communication link.Net Network 104 may include various connection types, such as wired, wireless communication link or fiber optic cables etc..
User 110 can be used terminal device 101,102,103 and be interacted by network 104 with server 105,106, to connect Receive or send message etc..Various telecommunication customer end applications can be installed, such as shopping class is answered on terminal device 101,102,103 With, searching class application, web browser applications, instant messaging tools, mailbox client, social platform software etc..
Terminal device 101,102,103 can be with display screen and the various electronics of data receiver and transmission supported to set It is standby, including but not limited to smart phone, tablet computer, E-book reader, MP3 player (Moving Picture Experts Group Audio Layer III, dynamic image expert's compression standard audio level 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic image expert's compression standard audio level 4) player, knee Mo(u)ld top half portable computer and desktop computer etc..
Server 105,106 can be to provide the server of various services, such as to sending out on terminal device 101,102,103 The operation requests sent provide the background server supported.Background server can divide the data such as the operation requests received The processing such as analysis, and processing result (such as the value corresponding with the keyword in operation requests found) is fed back into terminal and is set It is standby.
It should be noted that provided by the embodiment of the present application for send the methods of data generally by server 105, 106 execute, and correspondingly, the device for sending data is generally positioned in server 105,106.
It should be understood that the number of terminal device, network and server in Fig. 1 is only schematical.According to realization need It wants, can have any number of terminal device, network and server.
With continued reference to Fig. 2, the process of one embodiment of the method for sending data according to the application is shown 200.The method for sending data, comprising the following steps:
Step 201, whether the operation requests sent in response to receiving user terminal determine in operation requests comprising key Word.
In the present embodiment, the method for sending data runs electronic equipment (such as service described in Fig. 1 thereon Device) can by wired connection mode or radio connection from user using its to data (for example, keyword and with key The corresponding value of word) user terminal that is operated receives the operation requests that user sends, wherein and the operation requests can be Data storage request is also possible to data and increases request, can also be data modification request;Later, above-mentioned electronic equipment can be with It whether determines in aforesaid operations request comprising keyword, wherein above-mentioned keyword can be to be deposited with the structural body of preset fixed length The keyword of storage, above-mentioned keyword (Key, key) can be major key (Primary Key), can be in key assignments type database One or more fields, it is corresponding with keyword value (Value) for uniquely identify key assignments type database in it is a certain Item record.Structural body is by a series of data acquisition systems constituted with same type or different types of data, and structural body can To be declared as variable, pointer or array etc., to realize more complex data structure, structural body is also some elements simultaneously Set, these elements are known as the member (member) of structural body, and these members can be different types, and member generally uses name Word access.In actual items, research staff encapsulates some attributes commonly using structural body to form new type, it is therefore an objective to In order to simplify operation, allow user that need not be concerned about the attribute of construction inner, structure etc., it only need to be according to defining use ?.
Step 202, in response to determining that then keyword is converted into preset non-fixed comprising keyword in operation requests The keyword of long structural body storage, and whether further determine that in operation requests comprising value corresponding with keyword.
In the present embodiment, after determining in aforesaid operations request comprising keyword, above-mentioned electronic equipment can be In the accumulation layer of the bottom of key assignments type database, use dynamic memory arrangement algorithm to realize above-mentioned with preset fixed length The keyword of structural body storage is converted into no longer using the height of fixed length with the keyword of preset random length structural body storage The structural body for spending structuring carries out data storage, and uses the structural body storing data of the length dynamically changeable of compact, above-mentioned Dynamic memory arrangement algorithm can separate the storage organization of keyword and value corresponding with keyword, and later, above-mentioned electronics is set It is standby whether to determine in aforesaid operations request comprising 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 may include key length, also may include The metadata of keyword, can also include identify currently stored structure whether be " short length " flag bit, wherein above-mentioned member It is to data and information resources that data (Metadata), which are also known as broker data or relaying data as the data for describing data, Descriptive information, the information of data attribute is mainly described, for supporting that such as instruction storage location, historical data, resource are looked into It looks for and the functions such as file record.Above-mentioned electronic equipment can judge to identify currently stored according to the key length got The flag bit of " short length " of structure is 0 or 1, can be by key length less than 128 bytes (byte) (i.e. 0 to 127 word Section) the flag bit of " short length " of keyword be set as 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 as 1.Then, the above-mentioned keyword message got can be filled up to preset non-by above-mentioned electronic equipment In the structural body of fixed length, to generate with the keyword of preset random length structural body storage.
As an example, above-mentioned electronic equipment can be read first when carrying out data storage under Redis data storage method The keyword stored with robj storage unit (the most basic storage unit of redis object, primary Redis) is taken, and is obtained The key length of above-mentioned keyword then currently deposits mark in structural body when getting key length less than 128 byte The structure of storage is that the flag bit of " short length " is set as 0, and the key length that will acquire is filled up in length field, and will be closed Key word is filled up in buffer area, at this point, keyword can be described in the description information that 1 byte is used only, (i.e. flag bit is accounted for With 1 bit (bit), length information occupies 7 bits);When getting key length more than or equal to 128 byte, then by structure The flag bit that currently stored structure is " short length " is identified in body and is set as 1, and 4 bytes are used to indicate crucial word length before buffer area Degree, the 5th byte of buffer area is directed toward keyword, at this point, (i.e. flag bit is described to keyword using the description information of 5 bytes 1 bit is occupied, length information occupies 32 bits, separately there are 7 bits idle).
Step 203, it in response to determining not including value in operation requests, then searches and with preset random length structural body The corresponding value with preset random length structural body storage of the keyword of storage, later by it is being found, with preset The value of random length structural body storage is converted into the value stored with the structural body of preset fixed length, and sends and convert to user terminal Value afterwards.
In the present embodiment, the keyword that above-mentioned electronic equipment will can be stored with preset random length structural body in advance The corresponding relationship of the value with preset random length structural body storage 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 including value in aforesaid operations request, above-mentioned electronic equipment can be in key assignments type data It searches in library and is deposited with the keyword of preset random length structural body storage is corresponding with preset random length structural body The value of storage;Later, can by it is finding, be converted into preset fixed length with the value of preset random length structural body storage The value of structural body storage that is, no longer using the structural body storing data of the length dynamically changeable of compact, and uses the height of fixed length The structural body for spending structuring carries 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 above-mentioned with non-fixed length first Structural body storage value, and obtain it is above-mentioned with random length structural body storage value value information, wherein it is above-mentioned with non-fixed length The value information of value of structural body storage may include at least one of following: value length, the metadata of value, expired time mark Position, the least recently used time (LRU time), reference number (refcount) and identify currently stored value structure whether For the flag bit of " short length ", wherein the above-mentioned least recently used time be in memory but unused data block (memory Block) the least recently used time;Above-mentioned expired time flag bit is the flag bit for identifying whether to carry expired time;It is above-mentioned Metadata is also known as broker data or relaying data, is to the descriptive of data and information resources for the data for describing data Information mainly describes the information of data attribute, for supporting such as instruction storage location, historical data, resource lookup and file The functions such as record.Later, the value information of the above-mentioned value with the storage of random length structural body can be filled up to by above-mentioned electronic equipment The structural body of preset fixed length is (such as in Redis data storage method, using redis object as the structure of storage unit Body) in, to generate with the value of the structural body storage of preset fixed length.
With continued reference to the data acquisition behaviour that Fig. 3 a and Fig. 3 b, Fig. 3 a are according to the method for sending data of the present embodiment The flow chart of work, Fig. 3 b are the flow charts for increasing operation according to the data of the method for sending data of the present embodiment.In original In raw Redis data storage method, data are the structural bodies stored with robj storage unit, can will be calculated based on dynamic arrangement The data structure of the metadata of the storage keyword and value of method is named as magicKey and magicValue, hereinafter referred to as m.? In Fig. 3 a, when determining in operation requests that user terminal is sent comprising keyword, and not including value corresponding with keyword, The keyword a301 stored with robj storage unit is then converted into the keyword a302 stored with m storage unit;Later, in key The keyword a302 stored with m storage unit, the key-value pair 303 exported are as follows: keyword=pass are inputted in value type database Key word a, value=value a;Then, the value a304 stored with m storage unit is converted into the value a305 stored with robj storage unit; Finally, sending the value a305 after conversion to user terminal.In fig 3b, it is wrapped when in the operation requests for determining user terminal transmission Include value corresponding with keyword containing keyword, and when operation requests are that data increase request, then will be deposited with robj storage unit The keyword a306 of storage is converted into the keyword a307 stored with m storage unit, and the value that will be stored with robj storage unit A308 is converted into then storing by the keyword a307 stored with m storage unit and with m with the value a309 that m storage unit stores The value a309 of unit storage stores the increased key-value pair 310 are as follows: keyword=keyword a, value=value into key assignments type database a。
With further reference to Fig. 4, it illustrates the processes 400 of another embodiment of the method for sending data.The use In the process 400 for the method for sending data, comprising the following steps:
Step 401, whether the operation requests sent in response to receiving user terminal determine in operation requests comprising key Word.
In the present embodiment, the method for sending data runs electronic equipment (such as service described in Fig. 1 thereon Device) it can be connect from user using its user terminal operated to data by wired connection mode or radio connection Receive the operation requests that user sends, wherein the operation requests can be data storage request, is also possible to data increase and asks It asks, can also be data modification request;Later, whether above-mentioned electronic equipment can determine in aforesaid operations request comprising key A series of word, wherein structural body is by data acquisition systems constituted with same type or different types of data, and structural body can To be declared as variable, pointer or array etc., to realize more complex data structure, structural body is also some elements simultaneously Set, these elements are known as the member of structural body, and these members can be different types, and member generally uses name word access.
Step 402, in response to determining that then keyword is converted into preset non-fixed comprising keyword in operation requests The keyword of long structural body storage, and whether further determine that in operation requests comprising value corresponding with keyword.
In the present embodiment, after determining in aforesaid operations request comprising keyword, above-mentioned electronic equipment can be In the accumulation layer of the bottom of key assignments type database, use dynamic memory arrangement algorithm to realize above-mentioned with preset fixed length The keyword of structural body storage is converted into no longer using the height of fixed length with the keyword of preset random length structural body storage The structural body for spending structuring carries out data storage, and uses the structural body storing data of the length dynamically changeable of compact, above-mentioned Dynamic memory arrangement algorithm can separate the storage organization of keyword and value corresponding with keyword, and later, above-mentioned electronics is set It is standby to determine whether comprising value corresponding with above-mentioned keyword in aforesaid operations request, if in aforesaid operations request comprising with The corresponding value of above-mentioned keyword, thens follow the steps 404;If not including in aforesaid operations request corresponding with above-mentioned keyword Value, thens follow the steps 403.
Step 403, it in response to determining not including value in operation requests, then searches and with preset random length structural body The corresponding value with preset random length structural body storage of the keyword of storage, later by it is being found, with preset The value of random length structural body storage is converted into the value stored with the structural body of preset fixed length, and sends and convert to user terminal Value afterwards.
In the present embodiment, when not including value in aforesaid operations request, above-mentioned electronic equipment can be in key assignments type data It searches in library and is deposited with the keyword of preset random length structural body storage is corresponding with preset random length structural body The value of storage;Later, can by it is finding, be converted into preset fixed length with the value of preset random length structural body storage The value of structural body storage that is, no longer using the structural body storing data of the length dynamically changeable of compact, and uses the height of fixed length The structural body for spending structuring carries out data storage;Then, above-mentioned electronic equipment can send the value after conversion to user terminal.
Step 404, in response to determining that then value is converted into preset random length structure comprising value in operation requests The value of body storage.
In the present embodiment, after determining in aforesaid operations request comprising value, above-mentioned electronic equipment can be in key assignments In the accumulation layer of type database, dynamic memory arrangement algorithm is used to turn the value stored with the structural body of preset fixed length to realize It changes into the value of preset random length structural body storage, i.e., data is no longer carried out using the structural body of the highly structural of fixed length Storage, and use the structural body storing data 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 may include at least one of following: value length, value Metadata, expired time flag bit, the least recently used time, reference number and the currently stored value of mark structure be The no flag bit for " short length ", wherein the above-mentioned least recently used time be in memory but unused data block The least recently used time;Above-mentioned expired time flag bit is the flag bit for identifying whether to carry expired time;Above-mentioned member number According to also known as broker data or relaying data, for describe data data, be 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 Function.Above-mentioned electronic equipment can judge to identify the structure of currently stored value according to the value length got as " short length " Flag bit be 0 or 1, value length can be set as 0 less than the flag bit of " short length " of the value of 256 bytes;Length will be worth Flag bit more than or equal to " short length " of the value of 256 bytes is set as 1.Above-mentioned electronic equipment can also be according to the data got In whether carry expired time be arranged mark expired time flag bit be 0 or 1, do not carry expired time if getting, Then 0 is set by expired time flag bit;If getting carrying expired time, 1 is set by expired time flag bit.It Afterwards, above-mentioned value information can be filled up in above-mentioned preset random length structural body by above-mentioned electronic equipment, to generate with default Random length structural body storage value.
As an example, above-mentioned electronic equipment can be read first when carrying out data storage under Redis data storage method The value stored with robj storage unit is taken, and obtains in above-mentioned value whether carry expired time, it, will if not carrying expired time Expired time flag bit is set as 0, then obtains the value length of above-mentioned value, then will knot when getting value length less than 256 byte The flag bit that currently stored structure is " short length " is identified in structure body and is set as 0, and the 1st byte representation length of buffer area is delayed The 2nd byte direction value in area is rushed, at this point, the description information using 5 bytes value can be described (i.e. " short length " flag bit 1 bit, 1 bit of expired time mark bit occupancy are occupied, reference number occupies 6 bits, and the LRU time occupies 24 bits, length letter Breath occupies 8 bits);When the value length got is more than or equal to 256 byte, then currently stored structure will be identified in structural body It is set as 1 for the flag bit of " short length ", 4 bytes are used to indicate value length before buffer area, the 5th byte direction value of buffer area, this When, value can be described (i.e. " short length " mark 1 bit of bit occupancy, expired time mark using the description information of 8 bytes 1 bit of bit occupancy, reference number occupy 6 bits, and the LRU time occupies 24 bits, and length information occupies 32 bits).If carrying Time phase then sets 1 for expired time flag bit, preceding 4 byte representations expired time information of buffer area, then the storage being worth POS INT point 4 bytes of corresponding offset.
In the present embodiment, when carrying out data storage under Redis data storage method, what it is when storage is key length Less than 128 bytes, value length less than the String type of 256 bytes key-value pair when, using dynamic memory arrangement algorithm carry out Storage only needs the EMS memory occupation of the descriptive information of 6 bytes, and the primary data storage side based on robj storage unit Redis Formula needs the memory headroom of 56 bytes to store data.When the key for carrying out String type using dynamic memory arrangement algorithm When value is to storage, key length and value length are smaller, and the memory headroom of saving is bigger.
Step 405, determine that operation requests are that data increase request or data modification request.
In the present embodiment, above-mentioned electronic equipment can determine that aforesaid operations request is that data increase request or data are repaired Change request, be by keyword and/or value storage into key assignments type database or by key assignments type database with user terminal The corresponding value of keyword in the operation requests of transmission 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 increase request, then storage is with preset random length structure The value of body storage and the keyword stored with preset random length structural body.
In the present embodiment, when determining that aforesaid operations request is that data increase request, then above-mentioned electronic equipment can incite somebody to action It is above-mentioned to be arrived with the value of preset random length structural body storage and with the keyword storage of preset random length structural body storage In key assignments type database.
Step 407, it in response to determining that operation requests are data modification requests, then searches and with preset random length knot The identical keyword of keyword of structure body storage and value corresponding with keyword, and will value modification corresponding with keyword For with the value of preset random length structural body storage.
In the present embodiment, when determining that aforesaid operations request is data modification request, then above-mentioned electronic equipment can be first First searched in key assignments type database keyword identical with the above-mentioned keyword stored with preset random length structural body and The above-mentioned value stored in key assignments type database can be revised as above-mentioned user terminal later by value corresponding to the keyword The value with preset random length structural body storage after conversion in the operation requests of transmission.
Figure 4, it is seen that the method for sending data compared with the corresponding embodiment of Fig. 2, in the present embodiment Process 400 highlight in key assignments type database increase data the step of and in key assignments type database modify data step Suddenly.The structural body storing data that the scheme of the present embodiment description can also be variable using the length of compact as a result, thus more into One step improves memory usage.
With further reference to Fig. 5, as the realization to method shown in above-mentioned each figure, this application provides one kind for sending number According to device one embodiment, the Installation practice is corresponding with embodiment of the method shown in Fig. 2, which can specifically answer For in various electronic equipments.
As shown in figure 5, comprising determining that unit 501, conversion are single for sending the device 500 of data described in the present embodiment Member 502 and transmission unit 503.Wherein it is determined that unit 501 is configured to ask in response to the operation for receiving user terminal transmission It asks, whether determines in the operation requests comprising keyword, wherein the keyword is stored with the structural body of preset fixed length Keyword;Converting unit 502 is configured in response to determining comprising keyword in the operation requests, then by the key Word is converted into the keyword of preset random length structural body storage, and further determine that in the operation requests whether include Value corresponding with the keyword;Transmission unit 503 is configured in response to determining not including institute in the operation requests Value is stated, then is searched corresponding with preset random length knot with the keyword with preset random length structural body storage The value of structure body storage, later by it is being found, be converted into preset fixed with the value of preset random length structural body storage The value of long structural body storage, and the value after conversion is sent to the user terminal.
In the present embodiment, for sending the determination unit 501, converting unit 502 and transmission unit of the device 500 of data 503 specific processing and its brought technical effect can respectively with reference to step 201 in Fig. 2 corresponding embodiment, step 202 and The related description of the implementation of step 203, details are not described herein.
In some optional implementations of the present embodiment, the above-mentioned device 500 for sending data can also include Storage unit 504.After determining in aforesaid operations request comprising value, said memory cells 504 can be in key assignments type data In the accumulation layer of the bottom in library, dynamic memory arrangement algorithm is used to realize the value that will be stored with the structural body of preset fixed length It is converted into no longer being counted using the structural body of the highly structural of fixed length with the value of preset random length structural body storage According to storage, and use the structural body storing data of the length dynamically changeable of compact;Later, can determine aforesaid operations request is Data increase request or data modification request, are to store key keyword and/or value into key assignments type database still Value corresponding with the keyword in the operation requests that user terminal is sent is modified as user terminal transmission in value type database Value in operation requests;When determining that aforesaid operations request is that data increase request, then said memory cells 504 can will be above-mentioned With the value of preset random length structural body storage and with the keyword storage of preset random length structural body storage to key assignments In type database.
In some optional implementations of the present embodiment, the above-mentioned device 500 for sending data can also include Modify unit 505.When determining that aforesaid operations request is data modification request, then above-mentioned modification unit 505 can be first in key Keyword identical with the above-mentioned keyword with preset random length structural body storage is searched in value type database and to the pass The above-mentioned value stored in key assignments type database can be revised as what above-mentioned user terminal was sent later by the corresponding value of key word The value with preset random length structural body storage after conversion in operation requests.
In some optional implementations of the present embodiment, above-mentioned converting unit 502 may include obtaining module 5021 With fill in module 5022.Above-mentioned acquisition module 5021 can read above-mentioned keyword first, and obtain the key of above-mentioned keyword Word information, wherein above-mentioned keyword message may include key length, also may include the metadata of keyword, can be with Including identify currently stored structure whether be " short length " flag bit.Above-mentioned acquisition module 5021 can be according to getting Key length is 0 or 1 come the flag bit for judging to identify " short length " of currently stored structure, can be by key length Flag bit less than " short length " of the keyword of 128 bytes is set as 0;Key length is more than or equal to the key of 128 bytes The flag bit of " short length " of word is set as 1.Then, above-mentioned module 5022 of filling in can fill out the above-mentioned keyword message got It writes in preset random length structural body, to generate with the keyword of preset random length structural body storage.
In some optional implementations of the present embodiment, said memory cells 504 may include obtaining module 5041 With fill in module 5042.Above-mentioned acquisition module 5041 can read above-mentioned value corresponding with keyword first, and obtain above-mentioned The value information of value, wherein above-mentioned value information may include at least one of following: value length, the metadata of value, expired time mark Position, the least recently used time, reference number and the currently stored value of mark structure whether be " short length " flag bit. Above-mentioned acquisition module 5041 can judge to identify the structure of currently stored value according to the value length got as " short length " Flag bit be 0 or 1, value length can be set as 0 less than the flag bit of " short length " of the value of 256 bytes;Length will be worth Flag bit more than or equal to " short length " of the value of 256 bytes is set as 1.Above-mentioned acquisition module 5041 can also be according to getting Whether expired time is carried in data come the flag bit of mark expired time is arranged is 0 or 1, if getting when not carrying expired Between, then 0 is set by expired time flag bit;If getting carrying expired time, 1 is set by expired time flag bit. Later, above-mentioned value information can be filled up in above-mentioned preset random length structural body by above-mentioned module 5042 of filling in, to generate With the value of preset random length structural body storage.
In some optional implementations of the present embodiment, above-mentioned transmission unit 503 may include obtaining module 5031 With fill in module 5032.Above-mentioned acquisition module 5031 can read the above-mentioned value stored with random length structural body first, and obtain Take the value information of the above-mentioned value with the storage of random length structural body, wherein the value of the above-mentioned value with the storage of random length structural body Information may include at least one of following: value length, the metadata of value, expired time flag bit, the least recently used time, Reference number and identify currently stored value structure whether be " short length " flag bit.Later, above-mentioned to fill in module 5032 Can by it is above-mentioned with random length structural body storage value value information be filled up to preset fixed length structural body (such as In Redis data storage method, using redis object as the structural body of storage unit) in, to generate with preset fixed length Structural body storage value.
Below with reference to Fig. 6, it illustrates the computer systems 600 for the server for being suitable for being used to realize the embodiment of the present invention Structural schematic diagram.
As shown in fig. 6, computer system 600 includes central processing unit (CPU) 601, it can be read-only according to being stored in Program in memory (ROM) 602 or be loaded into the program in random access storage device (RAM) 603 from storage section 608 and Execute various movements appropriate and processing.In RAM603, also it is stored with system 600 and operates required various programs and data. CPU601, ROM602 and RAM603 are connected with each other by bus 604.Input/output (I/O) interface 605 is also connected to bus 604。
I/O interface 605 is connected to lower component: the importation 606 including keyboard, mouse etc.;It is penetrated including such as cathode The output par, c 607 of spool (CRT), liquid crystal display (LCD) etc. and loudspeaker etc.;Storage section 608 including hard disk etc.; And the communications portion 609 of the network interface card including LAN card, modem etc..Communications portion 609 via such as because The network of spy's net executes communication process.Driver 610 is also connected to I/O interface 605 as needed.Detachable media 611, such as Disk, CD, magneto-optic disk, semiconductor memory etc. are mounted on as needed on driver 610, in order to read from thereon Computer program be mounted into storage section 608 as needed.
Particularly, in accordance with an embodiment of the present disclosure, it may be implemented as computer above with reference to the process of flow chart description Software program.For example, embodiment of the disclosure includes a kind of computer program product comprising be tangibly embodied in machine readable Computer program on medium, above-mentioned computer program include the program code for method shown in execution flow chart.At this In the embodiment of sample, which can be downloaded and installed from network by communications portion 609, and/or from removable Medium 611 is unloaded to be mounted.
Flow chart and block diagram in attached drawing are illustrated according to the system of various embodiments of the invention, method and computer journey The architecture, function and operation in the cards of sequence product.In this regard, each box in flowchart or block diagram can generation A part of one module, program segment or code of table, a part of above-mentioned module, program segment or code include one or more Executable instruction for implementing the specified logical function.It should also be noted that in some implementations as replacements, institute in box The function of mark can also occur in a different order than that indicated in the drawings.For example, two boxes succeedingly indicated are practical On can be basically executed in parallel, they can also be executed in the opposite order sometimes, and this depends on the function involved.Also it wants It is noted that the combination of each box in block diagram and or flow chart and the box in block diagram and or flow chart, Ke Yiyong The dedicated hardware based system of defined functions or operations is executed to realize, or can be referred to specialized hardware and computer The combination of order is realized.
Being described in unit involved in the embodiment of the present invention can be realized by way of software, can also be by hard The mode of part is realized.Described unit also can be set in the processor, for example, can be described as: a kind of processor packet Include determination unit, converting unit and transmission unit.Wherein, the title of these units is not constituted under certain conditions to the unit The restriction of itself.For example, determination unit is also described as " in response to receiving the operation requests of user terminal transmission, really In the fixed operation requests whether include keyword unit ".
As on the other hand, the present invention also provides a kind of nonvolatile computer storage media, the non-volatile calculating Machine storage medium can be nonvolatile computer storage media included in above-mentioned apparatus in above-described embodiment;It is also possible to Individualism, without the nonvolatile computer storage media in supplying terminal.Above-mentioned nonvolatile computer storage media is deposited One or more program is contained, when said one or multiple programs are executed by an equipment, so that above equipment: response In the operation requests for receiving user terminal transmission, whether determine in the operation requests comprising keyword, wherein the key Word is the keyword stored with the structural body of preset fixed length;In response to determining comprising keyword in the operation requests, then The keyword is converted into the keyword of preset random length structural body storage, and further determines that the operation requests In whether include value corresponding with the keyword;In response to determining not including described value in the operation requests, then look into It looks for corresponding with the keyword with preset random length structural body storage with preset random length structural body storage Value, later by it is being found, be converted into the structure of preset fixed length with the value of preset random length structural body storage The value of body storage, and the value after conversion is sent to the user terminal.
Above description is only presently preferred embodiments of the present invention and the explanation to institute's application technology principle.Those skilled in the art Member is it should be appreciated that invention scope involved in the present invention, however it is not limited to technology made of the specific combination of above-mentioned technical characteristic Scheme, while should also cover in the case where not departing from the inventive concept, it is carried out by above-mentioned technical characteristic or its equivalent feature Any combination and the other technical solutions formed.Such as features described above has similar function with (but being not limited to) disclosed in the present invention Can technical characteristic replaced mutually and the technical solution that is formed.

Claims (12)

1. a kind of method for sending data, which is characterized in that the described method includes:
In response to receiving the operation requests of user terminal transmission, whether determine in the operation requests comprising keyword, wherein The keyword is the keyword stored with the structural body of preset fixed length;
In response to determining that then the keyword is converted into preset random length comprising keyword in the operation requests The keyword of structural body storage, and whether further determine that in the operation requests comprising value corresponding with the keyword;
In response to determining not including described value in the operation requests, then search and described with preset random length structural body The corresponding value with preset random length structural body storage of the keyword of storage, later by it is being found, with preset The value of random length structural body storage is converted into the value stored with the structural body of preset fixed length, and sends to the user terminal Value after conversion.
2. the method according to claim 1, wherein the method also includes:
In response to determining that then described value is converted into preset random length structure comprising described value in the operation requests The value of body storage, and determine that the operation requests are that data increase request or data modification request, it is described in response to determining Operation requests are that data increase request, then storage is described with the value of preset random length structural body storage and described with preset The keyword of random length structural body storage.
3. according to the method described in claim 2, it is characterized in that, the method also includes:
In response to determining that the operation requests are data modification requests, then search and described with preset random length structural body The identical keyword of the keyword of storage and value corresponding with the keyword, and will be described corresponding with the keyword Value be revised as the value with preset random length structural body storage.
4. the method according to claim 1, wherein described be converted into the keyword with preset non-fixed length Structural body storage keyword, comprising:
Read the keyword, and obtain the keyword message of the keyword, wherein the keyword message include with down toward One item missing: key length, the metadata of keyword;
The keyword message is filled up in preset random length structural body, to generate with preset random length structural body The keyword of storage.
5. according to the method described in claim 2, it is characterized in that, described will the value conversion corresponding with the keyword At with the value of preset random length structural body storage, comprising:
Described value is read, and obtains the value information of described value, wherein described value information includes at least one of the following: value length, value Metadata, expired time flag bit, the least recently used time and reference number;
By described value information solicitation into preset random length structural body, stored with generating with preset random length structural body Value.
6. the method according to claim 1, wherein described described will be stored with preset random length structural body Value be converted into the value stored with the structural body of preset fixed length, comprising:
The value with preset random length structural body storage is read, and is deposited described in acquisition with preset random length structural body The value information of the value of storage, wherein the value information of the value with preset random length structural body storage includes following at least one : value length, the metadata of value, expired time flag bit, least recently used time and reference number;
The value information of the value with preset random length structural body storage is filled up in the structural body of preset fixed length, with Generate the value stored with the structural body of preset fixed length.
7. a kind of for sending the device of data, which is characterized in that described device includes:
Determination unit is configured to the operation requests in response to receiving user terminal transmission, and determining in the operation requests is No includes keyword, wherein the keyword is the keyword stored with the structural body of preset fixed length;
Converting unit is configured in response to determining then to convert the keyword comprising keyword in the operation requests At with the keyword of preset random length structural body storage, and further determine that in the operation requests whether comprising with it is described The corresponding value of keyword;
Transmission unit is configured to then search with described with pre- in response to determining not including described value in the operation requests If the storage of random length structural body the corresponding value with preset random length structural body storage of keyword, later by institute It is finding, the value stored with the structural body of preset fixed length is converted into the value of preset random length structural body storage, and The value after conversion is sent to the user terminal.
8. device according to claim 7, which is characterized in that described device further include:
Storage unit is configured in response to determining in the operation requests comprising described value, then by described value be converted into The value of preset random length structural body storage, and determine that the operation requests are that data increase request or data modification is asked It asks, in response to determining that the operation requests are that data increase request, then storage is described is deposited with preset random length structural body The value of storage and the keyword with preset random length structural body storage.
9. device according to claim 8, which is characterized in that described device further include:
Unit is modified, is configured in response to determining that the operation requests are data modification requests, then is searched with described with pre- If the storage of random length structural body the identical keyword of keyword and value corresponding with the keyword, and will be described Value corresponding with the keyword is revised as the value with preset random length structural body storage.
10. device according to claim 7, which is characterized in that the converting unit includes:
Module is obtained, is configured to read the keyword, and obtain the keyword message of the keyword, wherein the pass Key word information includes at least one of the following: key length, the metadata of keyword;
Module is filled in, is configured to for the keyword message being filled up in preset random length structural body, to generate with pre- If random length structural body storage keyword.
11. device according to claim 8, which is characterized in that the storage unit includes:
Module is obtained, is configured to read described value, and obtain the value information of described value, wherein described value information includes following At least one of: value length, the metadata of value, expired time flag bit, least recently used time and reference number;
Module is filled in, is configured to by described value information solicitation into preset random length structural body, to generate with preset The value of random length structural body storage.
12. device according to claim 7, which is characterized in that the transmission unit includes:
Module is obtained, is configured to read the value with preset random length structural body storage, and obtain described with default The storage of random length structural body value value information, wherein the value of the value with preset random length structural body storage Information includes at least one of the following: value length, the metadata of value, expired time flag bit, least recently used time and draws Use number;
Module is filled in, is configured to for the value information of the value with preset random length structural body storage being filled up to preset In the structural body of fixed length, to generate with the value of the structural body storage of preset 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 CN106446272A (en) 2017-02-22
CN106446272B true 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)

Families Citing this family (2)

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

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPWO2003084077A1 (en) * 2002-03-25 2005-08-04 アライドテレシスホールディングス株式会社 Variable length / fixed length data conversion method and apparatus
US7779039B2 (en) * 2004-04-02 2010-08-17 Salesforce.Com, Inc. Custom entities and fields in a multi-tenant database system
CN101546342B (en) * 2009-05-08 2012-07-04 阿里巴巴集团控股有限公司 Method and system for implementing search service
JP5762878B2 (en) * 2011-08-08 2015-08-12 株式会社東芝 Memory system having a key-value store
CN103389992A (en) * 2012-05-09 2013-11-13 北京百度网讯科技有限公司 Structured data storage method and device
CN105373541B (en) * 2014-08-22 2019-03-22 博雅网络游戏开发(深圳)有限公司 The processing method and system of the data operation request of database

Also Published As

Publication number Publication date
CN106446272A (en) 2017-02-22

Similar Documents

Publication Publication Date Title
CN107818118B (en) Date storage method and device
CN105631035B (en) Date storage method and device
CN110019080B (en) Data access method and device
US10534753B2 (en) Caseless file lookup in a distributed file system
CN111291103B (en) Interface data analysis method and device, electronic equipment and storage medium
CN109657174A (en) Method and apparatus for more new data
CN107911456A (en) Flow optimization method, device, terminal device and the storage medium of picture loading
CN111950857A (en) Index system management method and device based on service indexes and electronic equipment
CN109447635A (en) Information storage means and device for block chain
CN108733317A (en) Date storage method and device
CN104657435A (en) Storage management method for application data and network management system
CN110019048A (en) Document handling method, device, system and server based on MongoDB
CN110706093A (en) Accounting processing method and device
US11308063B2 (en) Data structure to array conversion
CN106446272B (en) Method and apparatus for sending data
WO2020199659A1 (en) Method and apparatus for determining push priority information
US11093458B2 (en) Automatic attribute structural variation detection for not only structured query language database
CN112650804B (en) Big data access method, device, system and storage medium
CN110119386A (en) Data processing method, data processing equipment, medium and calculating equipment
CN109885593A (en) Method and apparatus for handling information
CN109697034A (en) A kind of method for writing data, device, electronic equipment and storage medium
CN111324258B (en) Method, device, equipment and medium for generating contents of configuration items of multilevel pull-down menu
CN110297945B (en) Data information processing method and system based on XBRL
CN110110184A (en) Information query method, system, computer system and storage medium
CN109597825B (en) Rule engine calling method, device, equipment and computer readable storage medium

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