A KV data storage method and device based on Redis protocol
By converting Redis protocol data into KV protocol data and storing it in the KV database, the problem of inconsistency in the master and slave node data in the Redis database is solved, and the strong consistent data storage is realized, which improves the flexibility and diversity of data storage.
Patent Information
- Application Number
- CN201910830696.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-09-04
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2039-09-04
AI Technical Summary
In the Redis database, during the data backup process based on the Redis protocol, the data of the master and slave nodes may be inconsistent due to the asynchronous replication of the master and slave nodes, especially when the network is disconnected for a long time or the master node is down, the data of the new master node will not be inconsistent. Complete, data consistency cannot be guaranteed.
By obtaining Redis protocol data, converting it into KV protocol data, and sending it to the KV database for storage, the KV database is used to ensure data consistency between master and slave nodes, and the strong consistent storage of Redis protocol data is achieved. The specific steps include obtaining the keywords and corresponding data of the Redis protocol data, obtaining the preset identifier according to the data type, obtaining the KV protocol data, and sending it to the KV database.
It ensures strong data consistency between the master and slave nodes of the Redis protocol data, solves the problem of inconsistent data backup in the Redis database, and improves the flexibility and diversity of data storage.
Smart Images

Figure CN110609766B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of distributed storage of financial technology (Fintech), and in particular to a KV data storage method and device based on the Redis protocol. Background Art
[0002] With the popularization of computers and the advancement of information technology, especially the rapid development of enterprise computer networks, the importance of enterprise information security has become increasingly apparent, and strict requirements have been put forward for data backup as an important part of enterprise information security. Redis database, a distributed storage database currently widely used by various enterprises, adopts the master-slave replication mode, that is, when one or more slave nodes are connected to the master node, the master node will copy the data to one or more slave nodes, thereby realizing multiple backups of the data. These backup data can greatly improve the read performance of the Redis service, and are also the basis for ensuring the high availability and distribution of the Redis service.
[0003] However, in the Redis database, when backing up data based on the Redis protocol, the data replication process from the master node to multiple slave nodes is performed asynchronously. This asynchronous replication method may cause inconsistency between the master and slave nodes, and thus cannot guarantee strong data consistency. For example, when the network is disconnected for a long time or the master node is down, the Redis database will elect a slave node as the new master node, but the original master node has not sent the latest data to the new master node for backup in time, resulting in incomplete data in the new master node. Summary of the invention
[0004] The present invention provides a KV data storage method and device based on the Redis protocol, which are used to solve the problem of inconsistent data backed up based on the Redis database.
[0005] In a first aspect, an embodiment of the present invention provides a KV data storage method based on the Redis protocol, the method comprising: obtaining Redis protocol data, obtaining a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type; according to the data type of the data corresponding to the first keyword, obtaining a preset identification symbol corresponding to the data type; based on the first keyword and the preset identification symbol, obtaining a second keyword; according to the second keyword and the data corresponding to the first keyword, obtaining KV protocol data, the preset identification symbol being used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword; and sending the KV protocol data to a KV database for storage.
[0006] Based on this solution, since the KV database can ensure data consistency between the master and slave nodes that apply the KV protocol data, this solution converts the acquired Redis protocol data into KV protocol data and sends it to the KV database for storage, thus helping to ensure strong data consistency between the master and slave nodes that apply the Redis protocol data.
[0007] In a possible implementation method, if the preset type is a string, the data corresponding to the first keyword includes a first value, and the preset identification symbol is the first identification character corresponding to the string; according to the data corresponding to the second keyword and the first keyword, KV protocol data is obtained, including: according to the second keyword and the first value, the KV protocol data is obtained.
[0008] In a possible implementation method, if the preset type is a hash or a set, the data corresponding to the first keyword includes a second value, the preset identifier is the second identifier corresponding to the hash, or is the third identifier corresponding to the set, and the second keyword includes a metadata keyword and an actual data keyword; the step of obtaining the second keyword based on the first keyword and the preset identifier includes: obtaining the metadata keyword based on the first keyword and the preset identifier; obtaining the actual data keyword based on the first keyword and the preset identifier; the method also includes: determining that the data corresponding to the metadata keyword includes a third value based on the number of elements corresponding to the first keyword; obtaining KV protocol data based on the second keyword and the data corresponding to the first keyword, including: obtaining the KV protocol data based on the second keyword, the second value and the third value, and the second value corresponds to the actual data keyword.
[0009] In a possible implementation method, if the preset type is a list, the data corresponding to the first keyword includes a fourth value, the preset identification symbol is the fourth identification character corresponding to the list, and the second keyword includes a metadata keyword and an actual data keyword; the step of obtaining the second keyword based on the first keyword and the preset identification symbol includes: obtaining the metadata keyword based on the first keyword and the fourth identification character; obtaining the actual data keyword based on the first keyword and the fourth identification character; the method also includes: determining that the data corresponding to the metadata keyword includes a fifth value based on the number of elements corresponding to the first keyword and the order of the elements; obtaining KV protocol data based on the second keyword and the data corresponding to the first keyword, including: obtaining the KV protocol data based on the second keyword, the fourth value and the fifth value, and the fourth value corresponds to the actual data keyword.
[0010] Based on the above three schemes, since the KV database can ensure the data consistency between the master and slave nodes that apply the KV protocol data, the above three schemes convert the acquired Redis protocol data of various data types into KV protocol data of the corresponding data types and send them to the KV database for storage. This helps to ensure the strong data consistency between the master and slave nodes that apply the Redis protocol data of various data types in the above three schemes, and realizes the conversion and storage of multiple data types, thereby improving the flexibility and diversity of data storage.
[0011] In a possible implementation method, a request message sent by a client is received; first KV protocol data corresponding to the request message is obtained; the first KV protocol data is converted into first Redis protocol data; and the first Redis protocol data is sent to the client.
[0012] In the embodiment of the present invention, based on the request of the client, the stored KV protocol data can be converted into Redis protocol data and then sent to the client.
[0013] In a second aspect, an embodiment of the present invention provides a KV data storage device based on the Redis protocol, the device comprising: a first acquisition unit, used to acquire Redis protocol data, acquire a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type; a second acquisition unit, used to acquire a preset identification symbol corresponding to the data type according to the data type of the data corresponding to the first keyword; a conversion unit, used to obtain a second keyword based on the first keyword and the preset identification symbol; and obtain KV protocol data according to the second keyword and the data corresponding to the first keyword, wherein the preset identification symbol is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword; and a communication unit, used to send the KV protocol data to a KV database for storage.
[0014] Based on this solution, since the KV database can ensure data consistency between the master and slave nodes that apply the KV protocol data, this solution converts the acquired Redis protocol data into KV protocol data and sends it to the KV database for storage, thus helping to ensure strong data consistency between the master and slave nodes that apply the Redis protocol data.
[0015] In one possible implementation method, if the preset type is a string, the data corresponding to the first keyword includes a first value, and the preset identification symbol is a first identification character corresponding to the string; the conversion unit is specifically used to obtain the KV protocol data based on the second keyword and the first value.
[0016] In one possible implementation method, if the preset type is a hash or a set, the data corresponding to the first keyword includes a second value, the preset identifier is the second identifier corresponding to the hash, or is the third identifier corresponding to the set, and the second keyword includes a metadata keyword and an actual data keyword; the conversion unit is specifically used to: obtain the metadata keyword based on the first keyword and the preset identifier; obtain the actual data keyword based on the first keyword and the preset identifier; determine, based on the number of elements corresponding to the first keyword, that the data corresponding to the metadata keyword includes a third value; obtain the KV protocol data based on the second keyword, the second value and the third value, and the second value corresponds to the actual data keyword.
[0017] In one possible implementation method, if the preset type is a list, the data corresponding to the first keyword includes a fourth value, the preset identification symbol is the fourth identification character corresponding to the list, and the second keyword includes a metadata keyword and an actual data keyword; the conversion unit is specifically used to: obtain the metadata keyword based on the first keyword and the fourth identification character; obtain the actual data keyword based on the first keyword and the fourth identification character; determine that the data corresponding to the metadata keyword includes a fifth value according to the number of elements corresponding to the first keyword and the order of the elements; obtain the KV protocol data according to the second keyword, the fourth value and the fifth value, and the fourth value corresponds to the actual data keyword.
[0018] Based on the above three schemes, since the KV database can ensure the data consistency between the master and slave nodes that apply the KV protocol data, the above three schemes convert the acquired Redis protocol data of various data types into KV protocol data of the corresponding data types and send them to the KV database for storage. This helps to ensure the strong data consistency between the master and slave nodes that apply the Redis protocol data of various data types in the above three schemes, and realizes the conversion and storage of multiple data types, thereby improving the flexibility and diversity of data storage.
[0019] In one possible implementation method, the communication unit is also used to receive a request message sent by a client; the first acquisition unit is also used to obtain first KV protocol data corresponding to the request message; the conversion unit is also used to convert the first KV protocol data into first Redis protocol data; the communication unit is also used to send the first Redis protocol data to the client.
[0020] Based on this solution, based on the client's request, the stored KV protocol data can be converted into Redis protocol data and then sent to the client.
[0021] In a third aspect, an embodiment of the present invention provides a computing device, including:
[0022] A memory for storing program instructions;
[0023] The processor is used to call the program instructions stored in the memory and execute any of the methods described above according to the obtained program.
[0024] In a fourth aspect, an embodiment of the present invention provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are used to enable a computer to execute any of the methods described above. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0026] Figure 1 A possible system architecture provided for an embodiment of the present invention;
[0027] Figure 2 A KV data storage method based on the Redis protocol provided in an embodiment of the present invention;
[0028] Figure 3 A method for calling Redis protocol data stored in KV encoding format provided by an embodiment of the present invention;
[0029] Figure 4 A KV data storage device based on the Redis protocol is provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical scheme and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] The embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings.
[0032] like Figure 1 As shown, a possible system architecture of an embodiment of the present invention is provided, based on which KV data storage based on the Redis protocol can be realized. The architecture includes a data storage device 102 and a database 103. Optionally, the architecture may also include a client 101.
[0033] Among them, the data storage device 102 is used to convert Redis protocol data into KV protocol data, and send the KV protocol data to the database 103 for storage; and, based on the request of the client 101, obtain KV protocol data from the database 103 and convert the KV protocol data into Redis protocol data, and then send the Redis protocol data to the client 101.
[0034] The database 103 is used to store data based on the KV protocol.
[0035] The client 101 is used to send a request message to the data storage device 102 to request to obtain Redis protocol data, and receive Redis protocol data from the data storage device 102.
[0036] based on Figure 1 In the system architecture, the embodiment of the present invention provides a KV data storage method based on the Redis protocol, which can be Figure 1 The data storage device 102 in the embodiment performs, Figure 2 As shown, the method comprises the following steps:
[0037] Step 201, obtaining Redis protocol data, obtaining a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type.
[0038] The data types of Redis protocol data include but are not limited to the following four types: string, hash, set, and list. Among them, Redis protocol data can be represented by Key-Value values.
[0039] Step 202: According to the data type of the data corresponding to the first keyword, obtain a preset identification symbol corresponding to the data type.
[0040] Step 203, obtain a second keyword based on the first keyword and the preset identifier; obtain KV protocol data according to the data corresponding to the second keyword and the first keyword, and the preset identifier is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword.
[0041] The data types of KV protocol data include but are not limited to the following four types: string, hash, set, and list. Among them, KV protocol data can be represented by Key-Value values.
[0042] When converting Redis protocol data to KV protocol data, if the data type of the Redis protocol data is a string, the data type of the converted KV protocol data is also a string; if the data type of the Redis protocol data is a hash, the data type of the converted KV protocol data is also a hash; if the data type of the Redis protocol data is a set, the data type of the converted KV protocol data is also a set; if the data type of the Redis protocol data is a list, the data type of the converted KV protocol data is also a list.
[0043] For Redis protocol data, String is a simple data type. Therefore, when Redis protocol data with data type String is converted to KV protocol data, the converted KV protocol data includes one data item, namely, actual data. Hash, Set and List are complex data types. Therefore, when Redis protocol data with data type Hash, Set or List is converted to KV protocol data, the converted KV protocol data includes at least two data items, namely metadata and actual data. The metadata mainly records additional information of the three types of data, Hash, Set or List. For example, when the data type is Hash or Set, the metadata information includes data capacity (Size), expiration time (Time to Live, TTL), flag (Flag), etc.; when the data type is List, the metadata information includes header information (Head), tail information (Tail), data capacity (Size), expiration time (Time to Live, TTL), flag (Flag), etc.
[0044] Step 204: Send the KV protocol data to a KV database for storage.
[0045] Based on this solution, since the KV database can ensure data consistency between the master and slave nodes that apply the KV protocol data, this solution converts the acquired Redis protocol data into KV protocol data and sends it to the KV database for storage, which helps to ensure strong data consistency between the master and slave nodes that apply the Redis protocol data. Therefore, when the Redis service is disconnected from the network for a long time or the master node is down, causing inconsistent data between the master and slave nodes, this solution helps to ensure data consistency between the master and slave nodes that apply the Redis protocol data.
[0046] The following is a specific implementation method for converting Redis protocol data into KV protocol data based on the data type of Redis protocol data.
[0047] Scenario 1: The data type of the Redis protocol data is String, and the Redis protocol data includes a first keyword and a first value.
[0048] The following is an example for explanation. As shown in Table 1, it is an example of information when the data type of Redis protocol data is String. A Redis protocol data of String type contains the keyword (Key) alice_account and the value (Value) 43000212333111110000.
[0049] The keyword (alice_account) here is also called the first keyword, and the value (43000212333111110000) here is also called the first value.
[0050] Table 1
[0051]
[0052] As shown in Table 2, the KV protocol data is obtained by converting the Redis protocol data shown in Table 1.
[0053] Table 2
[0054]
[0055] Refer to Table 2, where the second keyword is 1alice_account, and the keyword 1alice_account can also be called an actual data keyword. The second keyword 1alice_account is obtained based on the first keyword alice_account and the first identification character "1", that is, the first identification character "1" is added before the first keyword alice_account to obtain the second keyword 1alice_account, and the first identification character "1" is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword alice_account, both of which are String.
[0056] The value corresponding to the second keyword is 43000212333111110000, that is, the value corresponding to the second keyword is the same as the value corresponding to the first keyword, both of which are the first value.
[0057] Scenario 2: The data type of the Redis protocol data is Hash, and the Redis protocol data includes a first keyword and a second value.
[0058] The following is an example. Table 3 shows an example of information when the data type of Redis protocol data is Hash. A Redis protocol data of Hash type contains the keyword (Key) alice, and the values (Key) are name (Alice), age (18), country (China), and birthday (2000 / 1 / 1).
[0059] The keyword (alice) here is also called the first keyword, and the values (name(Alice), age(18), country(China), and birthday(2000 / 1 / 1)) here are also called the second values.
[0060] Table 3
[0061]
[0062]
[0063] As shown in Table 4, the KV protocol data is obtained by converting the Redis protocol data shown in Table 3.
[0064] Table 4
[0065]
[0066] Referring to Table 4, the second keywords are 2alice, 25alicename, 25aliceage, 25alicecountry and 25alicebirthday, wherein 2alice is a metadata keyword, and 25alicename, 25aliceage, 25alicecountry and 25alicebirthday are all actual data keywords.
[0067] For the second keyword 2alice, that is, in the metadata keyword of the second keyword, "2" is the second identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword alice, both of which are Hash. Specifically, add the second identification character "2" before the first keyword alice to obtain the second keyword 2alice. The values corresponding to the second keyword include 4201908081, wherein the first digit "4" in 4201908081 indicates that the number of elements corresponding to the first keyword is 4, that is, the number of elements corresponding to the actual data keyword in the KV protocol data obtained after conversion is 4. The number "4" can also be called the third value, and the third value is used as the data corresponding to the metadata keyword; the middle 8-digit number 20190808 represents TTL, and the last digit "1" represents Flag. Usually Flag is pre-defined, such as "1" for valid and "0" for expired.
[0068] For the second keyword 25alicename, that is, in the actual data keyword of the second keyword, the first keyword alice is included, and the name in the second value name (Alice); wherein, the first digit "2" in 25alicename is the second identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword alice, both of which are Hash; the second digit "5" in 25alicename is used to indicate that the string length of the first keyword alice is 5 characters. That is, the second keyword 25alicename is determined based on the first keyword alice, the name in the second value corresponding to the first keyword, the second identification symbol "2" and the string length of the first keyword alice.
[0069] For the other second keywords 25aliceage, 25alicecountry and 25alicebirthday, the meaning of each element can refer to the explanation of the second keyword 25alicename, which will not be repeated here.
[0070] The values corresponding to the second keywords 25alicename, 25aliceage, 25alicecountry and 25alicebirthday include a part of the second value, which are Alice, 19, China and 2000 / 1 / 1 respectively.
[0071] Scenario 3: The data type of the Redis protocol data is Set, and the Redis protocol data includes a first keyword and a second value.
[0072] The following is an example for explanation. As shown in Table 5, it is an example of information when the data type of Redis protocol data is Set. A Redis protocol data of Set type contains the keyword (Key) of favorite_fruits, and the values (Value) are apple, banana, and pear respectively.
[0073] The keyword (favorite_fruits) here is also called the first keyword, and the values (apple, banana, pear) here are also called the second values.
[0074] Table 5
[0075]
[0076] As shown in Table 6, the KV protocol data is obtained by converting the Redis protocol data shown in Table 5.
[0077] Table 6
[0078]
[0079]
[0080] Referring to Table 6, the second keywords are 3favorite_fruits, 315favorite_fruitsapple, 315favorite_fruitsbanana and 315favorite_fruitspear, wherein 3favorite_fruits is a metadata keyword, and 315favorite_fruitsapple, 315favorite_fruitsbanana and 315favorite_fruitspear are all actual data keywords.
[0081] For the second keyword 3favorite_fruits, that is, in the metadata keyword of the second keyword, "3" is the third identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword favorite_fruits, both of which are Set. Specifically, the third identification character "3" is added before the first keyword favorite_fruits to obtain the second keyword 3favorite_fruits. The values corresponding to the second keyword include 3201908081, wherein the first digit "3" in 3201908081 indicates that the number of elements corresponding to the first keyword is 3, that is, the number of elements corresponding to the actual data keyword in the KV protocol data obtained after conversion is 3. The number "3" can also be called the third value, and the third value is used as the data corresponding to the metadata keyword; the middle 8-digit number 20190808 indicates TTL, and the last digit "1" indicates Flag. Usually Flag is pre-defined, such as "1" indicates valid, and "0" indicates expired.
[0082] For the second keyword 315favorite_fruitsapple, that is, in the actual data keyword of the second keyword, the first keyword favorite_fruits is included, and the second value apple is also included; wherein, the first digit "3" in 315favorite_fruitsapple is the third identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword favorite_fruits, both of which are Set; the number "15" which is the sum of the second and third digits in 315favorite_fruitsapple is used to indicate that the string length of the first keyword favorite_fruits is 15 characters. That is, the second keyword 315favorite_fruitsapple is determined based on the first keyword favorite_fruits, the second value apple corresponding to the first keyword, the third identification character "3" and the string length of the first keyword favorite_fruits.
[0083] For the other second keywords 315favorite_fruitsbanana and 315favorite_fruitspear, the meaning of each element therein can refer to the explanation of the second keyword 315favorite_fruitsapple, which will not be repeated here.
[0084] The values corresponding to the second keywords 315favorite_fruitsapple, 315favorite_fruitsbanana and 315favorite_fruitspear include the second value, which are apple, banana and pear respectively.
[0085] Scenario 4: The data type of the Redis protocol data is List, and the Redis protocol data includes the first keyword and the fourth value.
[0086] The following is an example for explanation. As shown in Table 7, it is an example of information when the data type of Redis protocol data is List. A Redis protocol data of List type contains the keyword (Key) students_class_one, and the values (Value) are Grace, David, Peter, Daniel, and Mary.
[0087] Among them, the keyword (students_class_one) here is also called the first keyword, and the values (Grace, David, Peter, Daniel, Mary) here are also called the fourth values.
[0088] Table 7
[0089]
[0090] As shown in Table 8, the KV protocol data is obtained by converting the Redis protocol data shown in Table 7.
[0091] Table 8
[0092]
[0093] Referring to Table 8, the second keywords are 4students_class_one, 418students_class_one1, 418students_class_one2, 418students_class_one3, 418students_class_one4, and 418students_class_one5. Among them, 4students_class_one is a metadata keyword, and 418students_class_one1, 418students_class_one2, 418students_class_one3, 418students_class_one4, and 418students_class_one5 are all actual data keywords.
[0094] For the second keyword 4students_class_one, that is, in the metadata keyword of the second keyword, "4" is the fourth identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword students_class_one, both of which are List. Specifically, the fourth identification character "4" is added before the first keyword students_class_one to obtain the second keyword 4students_class_one. The values corresponding to the second keyword include 155201908081, wherein the first digit "1" in 155201908081 indicates that the sorting of the elements corresponding to the first keyword starts from "1", the second digit "5" indicates that the sorting of the elements corresponding to the first keyword ends at "5", and the third digit "5" indicates that the number of elements corresponding to the first keyword is 5, which means that the number of elements corresponding to the actual data keyword in the KV protocol data obtained after conversion is 5. The number "155" composed of the first digit "1", the second digit "5" and the third digit "5" can also be called the fifth value, and the fifth value is the data corresponding to the metadata keyword; the middle 8 digits 20190808 indicate TTL, and the last digit "1" indicates Flag, which is usually pre-defined, such as "1" for valid and "0" for expired.
[0095] For the second keyword 418students_class_one1, that is, in the actual data keyword of the second keyword, the first keyword students_class_one is included; wherein, the first digit "4" in 418students_class_one1 is the fourth identification character, which is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword students_class_one, both of which are List; the number "18" which is the sum of the second and third digits in 418students_class_one1 is used to indicate that the string length of the first keyword students_class_one is 18 characters, and the last digit "1" in 418students_class_one1 is used to indicate that the ranking of the fourth value Grace corresponding to the first keyword is 1. That is, the second keyword 418students_class_one1 is determined based on the first keyword students_class_one, the ranking of the fourth value Grace corresponding to the first keyword, the fourth identification symbol "4" and the string length of the first keyword students_class_one.
[0096] For the other second keywords 418students_class_one2, 418students_class_one3, 418students_class_one4 and 418students_class_one5, the meaning of each element therein can refer to the explanation of the second keyword 418students_class_one1, which will not be repeated here.
[0097] The values corresponding to the second keywords 418students_class_one1, 418students_class_one2, 418students_class_one3, 418students_class_one4 and 418students_class_one5 include the fourth value, which are Grace, David, Peter, Daniel and Mary respectively.
[0098] It should be noted that in the above examples, the first identification character in the KV protocol data of the String data type is "1", the second identification character in the KV protocol data of the Hash data type is "2", the third identification character in the KV protocol data of the Set data type is "3", and the fourth identification character in the KV protocol data of the List data type is "4". In actual applications, the definition of the preset identification symbols in the KV protocol data of different data types can also be adopted in other ways, which can be determined according to actual needs. For example, the above examples can also adopt the following method: the preset identification symbols in the KV protocol data of the String data type, Set data type, List data type and Hash data type are "1", "2", "3", "4" and so on respectively.
[0099] It should be noted that the preset identification symbol may be located at the first position of the second keyword, or at the last position of the second keyword, or may be at other positions, which is not limited in the present invention.
[0100] In an embodiment of the present invention, a method for calling Redis protocol data stored in a KV encoding format is also provided. Figure 3 As shown, the method comprises the following steps:
[0101] Step 301, receiving a request message from a client;
[0102] Step 302, obtaining first KV protocol data corresponding to the request message;
[0103] Step 303: convert the first KV protocol data into first Redis protocol data;
[0104] Step 304: Send the first Redis protocol data to the client.
[0105] Based on this solution, based on the client's request, the stored KV protocol data can be converted into Redis protocol data and then sent to the client.
[0106] Based on the same concept, the embodiment of the present invention also provides a KV data storage device based on the Redis protocol, such as Figure 4 As shown, the device comprises:
[0107] The first acquisition unit 401 is used to acquire Redis protocol data, and acquire a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type;
[0108] A second acquiring unit 402 is configured to acquire a preset identification symbol corresponding to the data type according to the data type of the data corresponding to the first keyword;
[0109] The conversion unit 403 obtains a second keyword based on the first keyword and the preset identifier; obtains KV protocol data according to the second keyword and the data corresponding to the first keyword, wherein the preset identifier is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword;
[0110] The communication unit 404 is used to send the KV protocol data to the KV database for storage.
[0111] Further, for the device, if the preset type is a string, the data corresponding to the first keyword includes a first value, and the preset identification symbol is the first identification character corresponding to the string; the conversion unit 403 is specifically used to obtain the KV protocol data according to the second keyword and the first value.
[0112] Further, for the device, if the preset type is a hash or a set, the data corresponding to the first keyword includes a second value, the preset identification symbol is the second identification character corresponding to the hash, or is the third identification character corresponding to the set, and the second keyword includes a metadata keyword and an actual data keyword; the conversion unit 403 is specifically used to: obtain the metadata keyword based on the first keyword and the preset identification symbol; obtain the actual data keyword based on the first keyword and the preset identification symbol; determine, according to the number of elements corresponding to the first keyword, that the data corresponding to the metadata keyword includes a third value; obtain the KV protocol data according to the second keyword, the second value and the third value, and the second value corresponds to the actual data keyword.
[0113] Further, for the device, if the preset type is a list, the data corresponding to the first keyword includes a fourth value, the preset identification symbol is the fourth identification character corresponding to the list, and the second keyword includes a metadata keyword and an actual data keyword; the conversion unit 403 is specifically used to: obtain the metadata keyword based on the first keyword and the fourth identification character; obtain the actual data keyword based on the first keyword and the fourth identification character; determine that the data corresponding to the metadata keyword includes a fifth value according to the number of elements corresponding to the first keyword and the order of the elements; obtain the KV protocol data according to the second keyword, the fourth value and the fifth value, and the fourth value corresponds to the actual data keyword.
[0114] Further, for the device, the communication unit 404 is also used to receive a request message from the client;
[0115] The first acquisition unit 401 is further configured to acquire first KV protocol data corresponding to the request message;
[0116] The conversion unit 403 is further used to convert the first KV protocol data into first Redis protocol data;
[0117] The communication unit 404 is further configured to send the first Redis protocol data to the client.
[0118] The embodiment of the present invention provides a computing device, which may be a desktop computer, a portable computer, a smart phone, a tablet computer, a personal digital assistant (PDA), etc. The computing device may include a central processing unit (CPU), a memory, an input / output device, etc. The input device may include a keyboard, a mouse, a touch screen, etc. The output device may include a display device, such as a liquid crystal display (LCD), a cathode ray tube (CRT), etc.
[0119] The memory may include a read-only memory (ROM) and a random access memory (RAM), and provides the processor with program instructions and data stored in the memory. In an embodiment of the present invention, the memory may be used for program instructions of a KV data storage method based on the Redis protocol;
[0120] The processor is used to call the program instructions stored in the memory and execute the KV data storage method based on the Redis protocol according to the obtained program.
[0121] An embodiment of the present invention provides a computer storage medium, wherein the computer storage medium stores computer executable instructions, and the computer executable instructions are used to enable a computer to execute a KV data storage method based on the Redis protocol.
[0122] It will be appreciated by those skilled in the art that embodiments of the present invention may be provided as methods or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0123] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.
[0124] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0125] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0126] Although the preferred embodiments of the present invention have been described, those skilled in the art may make other changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0127] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A KV data storage method based on the Redis protocol, characterized in that: include: Obtain Redis protocol data, obtain a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type; According to the data type of the data corresponding to the first keyword, obtaining a preset identification symbol corresponding to the data type; Based on the first keyword and the preset identifier, a second keyword is obtained; according to the second keyword and the data corresponding to the first keyword, KV protocol data is obtained, and the preset identifier is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword; wherein, when the preset type is a hash, or a set, or a list, the second keyword includes a metadata keyword and an actual data keyword, wherein the actual data keyword includes the preset identifier and a numerical value indicating the character string length of the first keyword; Sending the KV protocol data to a KV database for storage; Receive the request message sent by the client; Obtaining first KV protocol data corresponding to the request message; Convert the first KV protocol data into first Redis protocol data; The first Redis protocol data is sent to the client.
2. The method according to claim 1, characterized in that If the preset type is a string, the data corresponding to the first keyword includes a first value, and the preset identification symbol is a first identification character corresponding to the string; According to the data corresponding to the second keyword and the first keyword, KV protocol data is obtained, including: The KV protocol data is obtained according to the second keyword and the first value.
3. The method according to claim 1, characterized in that If the preset type is a hash or a set, the data corresponding to the first keyword includes a second value, and the preset identification symbol is a second identification character corresponding to the hash, or a third identification character corresponding to the set; The step of obtaining the second keyword based on the first keyword and the preset identification symbol comprises: Based on the first keyword and the preset identification symbol, obtaining the metadata keyword; Based on the first keyword and the preset identification symbol, obtaining the actual data keyword; The method further comprises: Determining, based on the number of elements corresponding to the first keyword, that the data corresponding to the metadata keyword includes a third value; According to the data corresponding to the second keyword and the first keyword, KV protocol data is obtained, including: The KV protocol data is obtained according to the second keyword, the second value and the third value, and the second value corresponds to the actual data keyword.
4. The method according to claim 1, characterized in that If the preset type is a list, the data corresponding to the first keyword includes a fourth value, and the preset identification symbol is a fourth identification character corresponding to the list; The step of obtaining the second keyword based on the first keyword and the preset identification symbol comprises: Based on the first keyword and the fourth identification character, obtaining the metadata keyword; Based on the first keyword and the fourth identification character, obtaining the actual data keyword; The method further comprises: Determining, according to the number of elements corresponding to the first keyword and the order of the elements, that the data corresponding to the metadata keyword includes a fifth value; According to the data corresponding to the second keyword and the first keyword, KV protocol data is obtained, including: The KV protocol data is obtained according to the second keyword, the fourth value and the fifth value, and the fourth value corresponds to the actual data keyword.
5. A KV data storage device based on the Redis protocol, characterized in that: include: A first acquisition unit is used to acquire Redis protocol data, and acquire a first keyword of the Redis protocol data and data corresponding to the first keyword, wherein the data type of the data corresponding to the first keyword is a preset type; A second acquiring unit, configured to acquire a preset identification symbol corresponding to the data type according to the data type of the data corresponding to the first keyword; A conversion unit, based on the first keyword and the preset identifier, obtains a second keyword; according to the second keyword and the data corresponding to the first keyword, obtains KV protocol data, wherein the preset identifier is used to indicate that the data type of the KV protocol data is consistent with the data type of the data corresponding to the first keyword; wherein, when the preset type is a hash, or a set, or a list, the second keyword includes a metadata keyword and an actual data keyword, wherein the actual data keyword includes the preset identifier and a numerical value indicating the character string length of the first keyword; A communication unit for sending the KV protocol data to a KV database for storage; The communication unit is further used to receive a request message sent by the client; The first acquisition unit is further used to acquire first KV protocol data corresponding to the request message; The conversion unit is further used to convert the first KV protocol data into first Redis protocol data; The communication unit is further used to send the first Redis protocol data to the client.
6. The device according to claim 5, characterized in that If the preset type is a string, the data corresponding to the first keyword includes a first value, and the preset identification symbol is a first identification character corresponding to the string; The conversion unit is specifically configured to obtain the KV protocol data according to the second keyword and the first value.
7. The device according to claim 5, characterized in that If the preset type is a hash or a set, the data corresponding to the first keyword includes a second value, and the preset identification symbol is a second identification character corresponding to the hash, or a third identification character corresponding to the set; The conversion unit is specifically used to: obtain the metadata keyword based on the first keyword and the preset identification symbol; Based on the first keyword and the preset identification symbol, obtaining the actual data keyword; According to the number of elements corresponding to the first keyword, determine that the data corresponding to the metadata keyword includes a third value; according to the second keyword, the second value and the third value, obtain the KV protocol data, and the second value corresponds to the actual data keyword.
8. The device according to claim 5, characterized in that If the preset type is a list, the data corresponding to the first keyword includes a fourth value, and the preset identification symbol is a fourth identification character corresponding to the list; The conversion unit is specifically configured to: obtain the metadata keyword based on the first keyword and the fourth identification character; Based on the first keyword and the fourth identification character, obtaining the actual data keyword; According to the number of elements corresponding to the first keyword and the order of the elements, it is determined that the data corresponding to the metadata keyword includes a fifth value; according to the second keyword, the fourth value and the fifth value, the KV protocol data is obtained, and the fourth value corresponds to the actual data keyword.
9. A computing device, characterized in that include: A memory for storing program instructions; A processor is used to call the program instructions stored in the memory and execute the method according to any one of claims 1 to 4 according to the obtained program.
10. A computer storage medium, characterized in that: The computer storage medium stores computer executable instructions, and the computer executable instructions are used to enable a computer to execute the method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Data storage structure conversion method and apparatus
CN105260464A