Method, apparatus, electronic device, and storage medium for processing multi-key-value commands

By grouping hash slots corresponding to key values ​​in database operations and executing multi-key value commands with multiple threads, the problem of low efficiency of multi-key value commands across hash slots in the prior art is solved, and more efficient database operations are achieved.

CN115039091BActive Publication Date: 2025-06-24SHENZHEN HEYTAP TECHNOLOGY CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202080095158.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-29
Publication Date
2025-06-24
Estimated Expiration
2040-05-29

AI Technical Summary

Technical Problem

The efficiency of the prior art when using multi-key value commands to operate a database still needs to be improved, especially when processing multi-key value commands across hash slots, which is less efficient.

Method used

When obtaining the multi-key value command for multiple key values, the hash slot corresponding to each key value is determined, and the multiple key values ​​are divided into multiple sets of key values, multiple second multi-key value instructions are generated based on each set of key values, and these instructions are executed using multiple threads.

Benefits of technology

Grouping hash slots corresponding to key values, and multi-threading multi-key value commands are used to execute multi-key value commands in parallel, significantly improving the execution efficiency of multi-key value commands across hash slots, thereby improving the efficiency of operating the database.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115039091B_ABST
    Figure CN115039091B_ABST
Patent Text Reader

Abstract

The present application discloses a method, apparatus, electronic device, and storage medium for processing multi-key-value commands. The method for processing multi-key-value commands includes: when a first multi-key-value command for multiple key values is obtained, determining hash slots corresponding to each key value among the multiple key values; when the hash slots corresponding to the multiple key values include multiple hash slots, dividing the multiple key values into multiple groups of key values according to the hash slots corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots; generating multiple second multi-key-value instructions according to each group of key values in the multiple groups of key values; and executing the multiple second multi-key-value commands by using multiple threads, where the second multi-key-value commands executed by each thread among the multiple threads are different. This method can implement the processing of multi-key-value commands across hash slots during database operations and can improve the speed of processing multi-key-value commands across hash slots.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of data processing, and more specifically, to a method, apparatus, electronic device, and storage medium for processing multi-key-value commands. Background Art

[0002] In current database technologies, clustering technology is a key technology for building high-performance websites. Database clustering technology can improve the reliability and performance of databases, and efficient data query and other operations can be achieved using database clusters. Among them, multi-key-value commands are often used for efficient operations on databases, but the efficiency of operating databases using multi-key-value commands still needs to be improved. Summary of the Invention

[0003] In view of the above problems, this application proposes a method, apparatus, electronic device, and storage medium for processing multi-key-value commands.

[0004] In a first aspect, an embodiment of this application provides a method for processing multi-key-value commands. The method includes: when a first multi-key-value command for multiple key values is obtained, determining the hash slot corresponding to each key value among the multiple key values; when the hash slots corresponding to the multiple key values include multiple hash slots, dividing the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond one-to-one with the multiple hash slots; generating multiple second multi-key-value instructions according to each group of key values in the multiple groups of key values; and executing the multiple second multi-key-value commands using multiple threads, where the second multi-key-value commands executed by each thread among the multiple threads are different.

[0005] In a second aspect, an embodiment of this application provides a device for processing multi-key-value commands. The device includes: a hash slot determination module, a key value grouping module, a command generation module, and a command execution module. The hash slot determination module is configured to determine the hash slot corresponding to each key value among the multiple key values when a first multi-key-value command for multiple key values is obtained; the key value grouping module is configured to divide the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value when the hash slots corresponding to the multiple key values include multiple hash slots, where the multiple groups of key values correspond one-to-one with the multiple hash slots; the command generation module is configured to generate multiple second multi-key-value instructions according to each group of key values in the multiple groups of key values; and the command execution module is configured to execute the multiple second multi-key-value commands using multiple threads, where the second multi-key-value commands executed by each thread among the multiple threads are different.

[0006] In a third aspect, an embodiment of the present application provides an electronic device, including: one or more processors; a memory; one or more applications, where the one or more applications are stored in the memory and configured to be executed by the one or more processors, and the one or more programs are configured to execute the multi-key value command processing method provided in the first aspect above.

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which program code is stored, and the program code can be called by a processor to execute the multi-key value command processing method provided in the first aspect above.

[0008] In the solution provided by the present application, when a first multi-key value command for multiple key values is obtained, the hash slot corresponding to each key value in the multiple key values is determined. When the hash slots corresponding to the multiple key values include multiple hash slots, the multiple key values are divided into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond to the multiple hash slots one by one. Multiple second multi-key value instructions are generated according to each group of key values in the multiple groups of key values, and multiple second multi-key value commands are executed by multiple threads, where the second multi-key value commands executed by each thread in the multiple threads are different. Therefore, when processing multi-key value commands across hash slots, grouping can be performed through the hash slots corresponding to the key values, and then the multi-key value commands can be executed in parallel by different threads according to the grouping, improving the execution efficiency of multi-key value commands across hash slots, and further improving the efficiency when operating on a database. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those skilled in the art, without creative efforts, other drawings can be obtained according to these drawings.

[0010] Figure 1 The flowchart of the multi-key value command processing method according to an embodiment of the present application is shown.

[0011] Figure 2 The flowchart of the multi-key value command processing method according to another embodiment of the present application is shown.

[0012] Figure 3 The flowchart of the multi-key value command processing method according to still another embodiment of the present application is shown.

[0013] Figure 4 The flowchart of the multi-key value command processing method according to yet another embodiment of the present application is shown.

[0014] Figure 5 A block diagram of a processing device for multi-key-value commands according to an embodiment of the present application is shown.

[0015] Figure 6 It is a block diagram of an electronic device for executing a processing method of multi-key-value commands according to an embodiment of the present application.

[0016] Figure 7 It is a storage unit for storing or carrying program codes for implementing a processing method of multi-key-value commands according to an embodiment of the present application. Detailed implementation manners

[0017] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application.

[0018] Due to the high reliability and high performance of the database cluster, the database cluster is often used to build websites. Currently, common databases include Redis (Remote Dictionary Server) databases. Redis is an open-source Key-Value database and provides APIs in multiple languages. Redis is a high-performance key-value storage system.

[0019] In the technology of Redis, although a single Redis node supports a query rate of more than 100,000 queries per second (QPS), as the access volume increases, Redis must be deployed in a cluster mode (Redis_cluster) to adapt to a higher query rate; at the same time, it supports the use of batch commands to reduce the number of network communications. Redis itself provides support for multi-key-value commands for the same hash slot, but when multiple key values are on different hash slots, cross-hash-slot multi-key-value commands are not supported by Redis.

[0020] The inventors have found through long-term research that in the related art, for cross-hash-slot multi-key-value commands in a Redis cluster, usually, for each different key value, N operations of key-value commands are performed to implement the multi-key-value command. However, operating on each key value requires executing commands multiple times, resulting in a longer waiting time for the caller and thus a lower efficiency in implementing cross-hash-slot multi-key-value commands.

[0021] In view of the above problems, the inventors propose a method, apparatus, electronic device, and storage medium for processing multi-key-value commands provided in the embodiments of the present application. When processing multi-key-value commands across hash slots in a Redis cluster, the key-value pairs are grouped according to the corresponding hash slots, and then different threads are used to execute the multi-key-value commands in parallel according to the grouping, which improves the execution efficiency of multi-key-value commands across hash slots, and further improves the efficiency when operating on the database. Among them, the specific method for processing multi-key-value commands will be described in detail in the subsequent embodiments.

[0022] Please refer to Figure 1 , Figure 1 which shows a schematic flowchart of a method for processing multi-key-value commands provided in an embodiment of the present application. In a specific embodiment, the method for processing multi-key-value commands is applied to a multi-key-value command processing apparatus 400 as shown in Figure 5 and an electronic device 100 configured with the multi-key-value command processing apparatus 400 ( Figure 6 ). Hereinafter, taking the electronic device as an example, the specific process of this embodiment will be described. Of course, it can be understood that the electronic device to which this embodiment is applied can be a mobile terminal, a tablet computer, a notebook computer, a PC computer, a server, etc., which is not limited herein. Next, the process shown in Figure 1 will be elaborated in detail. The method for processing multi-key-value commands may specifically include the following steps:

[0023] Step S110: When a first multi-key-value command for multiple key values is obtained, determine the hash slot corresponding to each key value among the multiple key values.

[0024] In the embodiments of the present application, when the electronic device obtains a first multi-key-value command for multiple key values, it can determine the hash slot corresponding to each key value among the multiple key values. Among them, the first multi-key-value command may be a command for operating on multiple key values in a Redis cluster, that is, a command for operating on multiple keys. Of course, the first multi-key-value command can also be used for other databases that can implement multi-key-value commands.

[0025] In some embodiments, the first multi-key-value command may include: multi-key-value commands for Redis clusters such as mget, mset, exist, del, msetnx, etc. Among them, the mget command and the msetnx command can be used to obtain data corresponding to multiple key values; the mset command can be used to set key-value data pairs corresponding to multiple key values; the exist command is used to store the data corresponding to the multiple key values; the del command can be used to delete the data corresponding to the multiple key values. Of course, the types of multi-key-value commands are not limited to this, and can also be other multi-key-value commands.

[0026] In the embodiments of the present application, since if the first multi-key value command for operating on multiple key values is a command across hash slots, that is, multiple key values may be distributed in at least two different hash slots, the first multi-key value command cannot be directly executed. Therefore, when the electronic device obtains the first multi-key value command for multiple key values, it can determine the hash slot corresponding to each key value among the multiple key values, so as to subsequently determine whether the first multi-key value command is a multi-key value command across hash slots.

[0027] Among them, Redis introduced the cluster feature in version 3.0. The Redis cluster includes multiple nodes that are interconnected with each other. The electronic device can act as a client and connect to any node, and then can access any node in the cluster to perform operations such as data storage and retrieval. Each node in Redis has hash slots. A hash slot can store a variable with two values, and the value range of this variable is 0 to 16383. When operating on a key value, usually the hash slot corresponding to the key is calculated, that is, one of 0 to 16383, and then according to this value, the node corresponding to the hash slot is found, and the corresponding operation on the key is realized through interaction with the node. Therefore, it is possible to calculate the hash slot corresponding to each key value among the multiple key values corresponding to the above first multi-key value command, so as to subsequently determine whether the first multi-key value command is a multi-key value command across hash slots. In addition, it is also convenient to determine the node where the key value is located, so as to interact with the node to realize the operation on the key value.

[0028] Step S120: When the hash slots corresponding to the multiple key values include multiple hash slots, divide the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots.

[0029] In the embodiments of the present application, after the electronic device determines the hash slot corresponding to each key value among the multiple key values corresponding to the above first multi-key value command, it can determine whether the multiple hash slots corresponding to the multiple key values include multiple hash slots. It can be understood that the hash slots corresponding to multiple key values may be the same hash slot or different hash slots. Therefore, the multiple hash slots corresponding to multiple key values may include multiple hash slots or may only include one hash slot.

[0030] When the electronic device determines that the hash slots corresponding to the above multiple key values include multiple hash slots, that is, the hash slots corresponding to the multiple key values are different hash slots. At this time, since Redis itself provides support for multi-key value commands for the same hash slot, but when multiple key values are on different hash slots, multi-key value commands across hash slots are not supported by Redis. Therefore, this situation needs to be processed to realize the implementation of multi-key value commands across hash slots.

[0031] In the embodiments of the present application, considering that in the related art, in the implementation manner of multi-key-value commands across hash slots, corresponding operation commands are sequentially executed for different key-values to implement multi-key-value commands across hash slots. However, this requires executing commands multiple times, resulting in low efficiency in implementing multi-key-value commands across hash slots. Therefore, multiple key-values can be divided into multiple groups of key-values according to the hash slots corresponding to each key-value.

[0032] In some embodiments, the electronic device can group multiple key-values according to the hash slots corresponding to each key-value and different hash slots to obtain multiple groups of key-values. Among the obtained multiple groups of key-values, the multiple groups of key-values correspond one-to-one with multiple hash slots. That is to say, the hash slots corresponding to the key-values in different groups are different. For example, multiple key-values include: key1, key2, key3, key4, key5, and key6. The first group of key-values includes: key1 and key3, and the hash slot numbers corresponding to key1 and key3 are 11121. The second group of key-values includes: key4 and key6, and the hash slot numbers corresponding to key4 and key6 are 10428. The third group of key-values includes: key2 and key5, and the hash slot numbers corresponding to key2 and key5 are 2356.

[0033] Step S130: Generate multiple second multi-key-value commands according to each group of key-values in the multiple groups of key-values.

[0034] In the embodiments of the present application, after the electronic device groups multiple key-values according to their corresponding different hash slots to obtain multiple groups of key-values. Since it is necessary to implement the first multi-key-value command for multiple key-values to implement the operation corresponding to the first multi-key-value command for multiple key-values, the electronic device can generate multiple second multi-key-value commands according to each group of key-values in the multiple groups of key-values. Subsequently, by executing these second multi-key-value commands, the operation corresponding to the first multi-key-value command for multiple key-values can be implemented.

[0035] In some embodiments, the electronic device can generate corresponding second multi-key-value commands according to each group of key-values in the multiple groups of key-values, in accordance with the type corresponding to the first multi-key-value command and the command content for the key-values in each group of key-values. That is to say, the operation implemented by each second multi-key-value command is the same as the operation of the key-value corresponding to the second multi-key-value command in the first multi-key-value command. Thus, by subsequently executing these second multi-key-value commands, the operation corresponding to the first multi-key-value command for multiple key-values can be implemented.

[0036] Step S140: Execute the multiple second multi-key-value commands by using multiple threads, where each thread in the multiple threads executes a different second multi-key-value command.

[0037] In an embodiment of the present application, after an electronic device generates a plurality of second multi-key value commands, to improve the execution efficiency of multi-key value commands across hash slots, multiple threads can be used to execute these multiple second multi-key value commands. Moreover, the multiple threads correspond one-to-one with the multiple second multi-key value commands, and the second multi-key value commands executed by each thread are different. Thus, it can be ensured that each second multi-key value command is separately executed by a thread, realizing parallel execution of multiple second multi-key value commands and effectively improving the processing efficiency.

[0038] The method for processing multi-key value commands provided by the embodiment of the present application, when obtaining a first multi-key value command for multiple key values, determines the hash slot corresponding to each key value among the multiple key values. When the hash slots corresponding to the multiple key values include multiple hash slots, according to the hash slot corresponding to each key value, the multiple key values are divided into multiple groups of key values, where the multiple groups of key values correspond one-to-one with the multiple hash slots. According to each group of key values in the multiple groups of key values, multiple second multi-key value instructions are generated, and multiple threads are used to execute the multiple second multi-key value commands, where the second multi-key value commands executed by each thread among the multiple threads are different. Thus, when processing multi-key value commands across hash slots, grouping can be performed through the hash slots corresponding to the key values, and then different threads are used to execute the multi-key value commands in parallel according to the grouping, improving the execution efficiency of multi-key value commands across hash slots, and further improving the efficiency when operating on a database.

[0039] Please refer to Figure 2 , Figure 2 FIG. shows a schematic flowchart of a method for processing multi-key value commands provided by another embodiment of the present application. The method for processing multi-key value commands can be applied to the above-mentioned electronic device. The following will elaborate in detail on Figure 2 the process shown in FIG., and the method for processing multi-key value commands may specifically include the following steps:

[0040] Step S210: When obtaining a first multi-key value command for multiple key values, calculate the hash slot corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm.

[0041] In an embodiment of the present application, when an electronic device obtains a first multi-key value command for multiple key values, it can calculate the hash slot corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm (CRC), so as to determine whether the first multi-key value command is a multi-key value command across hash slots subsequently.

[0042] In some embodiments, calculating the hash slot corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm may include:

[0043] Calculate the value corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm; obtain the remainder of the value corresponding to each key value divided by the total number of hash slots corresponding to the database cluster, and obtain the number of the hash slot corresponding to each key value.

[0044] In this embodiment, the cyclic redundancy check algorithm may be the CRC16 algorithm. Through the CRC16 algorithm, a value can be calculated according to each key value, and then by taking the remainder of this value divided by the total number of hash slots corresponding to the database cluster, the number of the hash slot corresponding to each key value can be obtained. That is to say, the hash slot to which the key belongs can be calculated according to the formula slot = CRC16(key) % 16384, where slot is the hash slot, % is the remainder operator, and the CRC16(key) statement is used to calculate the CRC16 checksum of key.

[0045] Step S220: When the hash slots corresponding to the multiple key values include one hash slot, execute the first multi-key value command.

[0046] In the embodiment of the present application, after the electronic device determines the hash slot corresponding to each key value among the multiple key values, it can determine whether the hash slots corresponding to the multiple key values include multiple hash slots. When the electronic device determines that the hash slots corresponding to the above multiple key values include one hash slot, that is, the hash slots corresponding to the multiple key values are the same hash slot, at this time, since Redis itself provides support for multi-key value commands for the same hash slot, the electronic device can directly execute the first multi-key value command, thereby completing the operation corresponding to the first multi-key value command for the multiple key values.

[0047] Step S230: When the hash slots corresponding to the multiple key values include multiple hash slots, divide the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots.

[0048] Step S240: Generate multiple second multi-key value instructions according to each group of key values in the multiple groups of key values.

[0049] Step S250: Use multiple threads to execute the multiple second multi-key value commands, where the second multi-key value commands executed by each thread among the multiple threads are different.

[0050] In the embodiment of the present application, the content of steps S230 to S250 may refer to the content of the foregoing embodiment and will not be elaborated here.

[0051] Step S260: When the first multi-key value command is used to obtain the data corresponding to the multiple key values, merge the obtained data according to the order in which the data is passed in, and obtain the data corresponding to each key value among the multiple key values.

[0052] In an embodiment of the present application, the first multi-key-value command may be used to obtain data corresponding to multiple key values. When the first multi-key-value command is used to obtain data corresponding to multiple key values, and if the hash slots corresponding to the multiple key values of the first multi-key-value command include multiple hash slots, the second multi-key-value command will be executed in parallel by multiple threads to obtain the data corresponding to each key value. It can be understood that since the second multi-key-value command is executed in parallel by multiple threads to obtain the data corresponding to each key value, in order to ensure obtaining the correct key-value correspondence, it is necessary to merge the obtained results in order. In some embodiments, the electronic device may establish the correspondence between each key value and each data among the multiple key values according to the order in which the data is received, and obtain the data corresponding to each key value according to the correspondence, so that the data corresponding to each key can be correctly obtained in the finally obtained result.

[0053] In some embodiments, the electronic device may interact with the Redis database as a client, so that from the perspective of the client, a multi-key-value command across hash slots can be implemented, and the parallel advantage of multiple threads is used to reduce the waiting time of the client and improve the performance of the client program. When the electronic device is used as a client, it can calculate the nodes corresponding to the hash slots according to the hash slots corresponding to each key value, and then access the corresponding nodes according to the multi-key-value command to implement the operation of the key values in the corresponding hash slots of the corresponding nodes.

[0054] The method for processing a multi-key-value command provided by the embodiment of the present application, when obtaining the first multi-key-value command for multiple key values, calculates the hash slot corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm. When the hash slots corresponding to the multiple key values only include one hash slot, the first multi-key-value command is directly executed to implement the corresponding operation on these multiple key values this time. When the hash slots corresponding to the multiple key values include multiple hash slots, according to the hash slot corresponding to each key value, the multiple key values are divided into multiple groups of key values, where the multiple groups of key values correspond one-to-one to the multiple hash slots. According to each group of key values in the multiple groups of key values, multiple second multi-key-value instructions are generated, and multiple second multi-key-value commands are executed by multiple threads, where the second multi-key-value commands executed by each thread in the multiple threads are different, so that a multi-key-value operation across hash slots can be implemented, grouping is performed using different hash slots, reducing the read and write time for operating on a single key value in the related art, and using the technical solution of multiple threads to execute the operations on multiple key values in parallel, reducing the execution time and complexity of serial calls.

[0055] Please refer to Figure 3 , Figure 3The flowchart shows a method for processing multi-key-value commands provided by another embodiment of the present application. The method for processing multi-key-value commands can be applied to the above-mentioned electronic device. The following will elaborate on the Figure 3 shown process in detail. The method for processing multi-key-value commands can specifically include the following steps:

[0056] Step S310: When a first multi-key-value command for multiple key values is obtained, determine the hash slot corresponding to each key value among the multiple key values.

[0057] Step S320: When the hash slots corresponding to the multiple key values include multiple hash slots, divide the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots.

[0058] Step S330: Generate multiple second multi-key-value instructions according to each group of key values in the multiple groups of key values.

[0059] In the embodiments of the present application, steps S310 to S330 can refer to the content of the foregoing embodiments and will not be elaborated herein.

[0060] Step S340: Assign each second multi-key-value command among the multiple second multi-key-value commands to one thread among multiple threads, and the threads corresponding to each second multi-key-value command are different.

[0061] In the embodiments of the present application, when using multiple threads to execute multiple second multi-key-value commands, the electronic device can assign each second multi-key-value command among the multiple second multi-key-value commands to one thread among multiple threads, and the threads corresponding to each second multi-key-value command are different. That is to say, for each second multi-key-value command, a different thread is assigned so that multiple threads can execute the assigned second multi-key-value commands in parallel.

[0062] In some embodiments, the electronic device can create a thread pool and initialize the thread pool. The electronic device can assign a different thread from the thread pool to each second multi-key-value command, and each thread is used to separately execute the second multi-key-value command assigned to it.

[0063] In some embodiments, the electronic device can use a thread pool to assign threads to the second multi-key-value commands. Among them, the thread pool is a form of multi-threaded processing that can assign tasks to threads, and the threads can automatically execute the tasks. A thread pool can be pre-created in the electronic device or created when data needs to be pushed. For example, the electronic device can create a thread pool by using the ThreadPoolExecutor class or the Executors class. The specific way of creating the thread pool can not be limited.

[0064] In this embodiment, the electronic device can obtain the available threads in the thread pool. Herein, the available threads can refer to the threads in the idle state, that is, the threads without tasks to be executed. The available threads can be used to execute a multi-key-value command to perform corresponding operations on the key values corresponding to the multi-key-value command.

[0065] In some ways, after the electronic device determines the available threads from the thread pool, it can allocate a second multi-key-value command to each of the threads in the available threads. Herein, each second multi-key-value command should ensure that it is allocated to an available thread to ensure that the operations corresponding to the commands can be performed on the multiple key values corresponding to the first multi-key-value command.

[0066] In some ways, after the electronic device determines the available threads, it can also determine the number of available threads, compare this number with the number corresponding to multiple second multi-key-value commands, and determine whether the number of available threads is less than the number corresponding to multiple second multi-key-value commands according to the comparison result. If the number of available threads is greater than or equal to the number corresponding to multiple second multi-key-value commands, it means that the current available threads can ensure that each second multi-key-value command is allocated to a different thread. Therefore, each second multi-key-value command in the multiple second multi-key-value commands can be allocated to one of the available threads. If the number of available threads is less than the number corresponding to multiple second multi-key-value commands, it means that the current available threads cannot ensure that each second multi-key-value command is allocated to a different thread. At this time, it is necessary to ensure that all the second multi-key-value commands can be allocated to threads to complete the operations corresponding to the commands on the multiple key values corresponding to the first multi-key-value command.

[0067] Furthermore, if the number of available threads is less than the number corresponding to multiple second multi-key-value commands, target number of threads can be created in the thread pool, where the sum of the target number and the number of the available threads is greater than or equal to the number corresponding to multiple second multi-key-value commands. Herein, the electronic device can request to allocate the available resources of the processor to create the target number of new threads into the thread pool, and the sum of the target number and the number of the available threads is greater than or equal to the number corresponding to multiple second multi-key-value commands. Thus, after creating the threads, the number of available threads can ensure that each second multi-key-value command is allocated to a different thread.

[0068] In this embodiment, before creating a thread and adding it to the thread pool, the electronic device may also obtain the load rate of the processor, then compare the load rate with a specified load rate, and determine whether the load rate is less than the specified load rate according to the comparison result. Herein, the specified load rate is used to determine whether the load of the processor is high. If the load rate is less than the specified load rate, it indicates that the load of the processor is not high. Therefore, only the target number of threads may be created in the thread pool. If the load rate is greater than or equal to the specified load rate, it indicates that the load of the processor is high and it is not suitable to create new threads and add them to the thread pool.

[0069] In some embodiments, if the load rate is greater than or equal to the specified load rate, the electronic device may adopt a method of respectively assigning at least two second multi-key-value commands to the same thread to ensure that all second multi-key-value commands are assigned to threads, so as to complete the operations corresponding to the commands for the multiple key values corresponding to the first multi-key-value command.

[0070] As a method, when the first multi-key-value command is used to obtain the data corresponding to each key value among multiple key values, if the load rate is greater than or equal to the specified load rate, the electronic device may determine the data volume of the data corresponding to each second multi-key-value command among the multiple second multi-key-value commands, and then respectively assign at least two second multi-key-value commands to the same thread according to the data volume, and make the size of the data volume obtained by each thread basically consistent.

[0071] For example, there are 8 second multi-key-value commands, namely multi-key-value command 1, multi-key-value command 2, multi-key-value command 3, multi-key-value command 4, multi-key-value command 5, multi-key-value command 6, multi-key-value command 7, and multi-key-value command 8. The data volume corresponding to multi-key-value command 1 is 200 megabytes (Mb), the data volume corresponding to multi-key-value command 2 is 300 Mb, the data volume corresponding to multi-key-value command 3 is 500 Mb, the data volume corresponding to multi-key-value command 4 is 300 Mb, the data volume corresponding to multi-key-value command 5 is 200 Mb, the data volume corresponding to multi-key-value command 6 is 150 Mb, the data volume corresponding to multi-key-value command 7 is 150 Mb, and the data volume corresponding to multi-key-value command 8 is 210 Mb. Then, multi-key-value command 1 and multi-key-value command 4 may be assigned to the same thread, multi-key-value command 2 and multi-key-value command 5 may be assigned to the same thread, multi-key-value command 4 may be assigned to the same thread, and multi-key-value command 6, multi-key-value command 7, and multi-key-value command 8 may be assigned to the same thread, so that the data volume obtained by each thread is about 500 Mb.

[0072] In some embodiments, if the load ratio is greater than or equal to the specified load ratio, the electronic device can also determine the priorities of the tasks executed by the currently non-idle threads, and can allocate the second most key-value commands to the threads corresponding to the tasks with lower priorities to implement the corresponding operations on the multiple key-values. After completing the operations on the multiple key-values this time, these threads then execute the previous tasks. Among them, the priority can be determined according to the real-time nature of the task. For example, the real-time nature is determined according to the task type.

[0073] Step S350: Each thread sends the corresponding second multi-key-value command to the server.

[0074] In the embodiments of the present application, after the electronic device allocates a different thread to each second multi-key-value command, the electronic device can calculate the nodes corresponding to the hash slots corresponding to each second multi-key-value command, and each thread can send the second multi-key-value command to these nodes of the Redis server to complete the operations on the key-values in the corresponding hash slots in the corresponding nodes.

[0075] The method for processing multi-key-value commands provided by the embodiments of the present application, when processing multi-key-value commands across hash slots, groups them according to the hash slots corresponding to the key-values, and then uses different threads to execute the multi-key-value commands in parallel according to the groups, which improves the execution efficiency of the multi-key-value commands across hash slots, and further improves the efficiency when operating on the database. Moreover, when allocating threads for the second multi-key-value commands corresponding to each group, considering the number of available threads and reasonably allocating threads according to the number of available threads can ensure the operations corresponding to the multi-key-value commands for multiple key-values.

[0076] Please refer to Figure 4 , Figure 4 shows a schematic flowchart of a method for processing multi-key-value commands provided by another embodiment of the present application. This method for processing multi-key-value commands can be applied to the above-mentioned electronic device. The following will elaborate in detail on the Figure 4 shown process. The method for processing multi-key-value commands can specifically include the following steps:

[0077] Step S410: When obtaining the first multi-key-value command for multiple key-values, determine the hash slot corresponding to each key-value among the multiple key-values.

[0078] Step S420: When the hash slots corresponding to the multiple key-values include multiple hash slots, divide the multiple key-values into multiple groups of key-values according to the hash slot corresponding to each key-value, where the multiple groups of key-values correspond one-to-one to the multiple hash slots.

[0079] Step S430: Generate multiple second multi-key-value instructions according to each group of key-values in the multiple groups of key-values.

[0080] In the embodiments of the present application, steps S410 to S430 may refer to the content of the foregoing embodiments and will not be elaborated herein.

[0081] Step S440: When the first multi-key value command is used to obtain the data corresponding to the multiple key values, each thread, according to the corresponding second multi-key value command, after obtaining a preset amount of data, sends the obtained data to the service end.

[0082] In some application scenarios, an electronic device can, in response to the query requirements of the service end, query the data of multiple key values from a Redis database, and after querying the corresponding data, return it to the service end to meet the requirements of the service end.

[0083] In the embodiments of the present application, when the first multi-key value command is used to obtain the data corresponding to each key value among the multiple key values, each thread, according to the corresponding second multi-key value command, after obtaining a preset amount of data, sends the obtained data to the service end. That is to say, after each thread obtains a batch of data, it stores the obtained data in the memory, and then sends the obtained data from the memory. In this way, when the amount of data to be queried is large, batch query of data is adopted to avoid excessive memory occupation of the electronic device, resulting in a stuck situation. Of course, after the electronic device obtains a preset amount of data, it can also integrate the data according to the order in which the data is received, so as to facilitate determining the data corresponding to each key value, that is, clarifying the key-value correspondence. By obtaining and sending the data corresponding to the key values in batches, the effect of obtaining and sending while obtaining can also be achieved. And because multiple threads simultaneously obtain the multi-key value data of different hash slots, compared with the serial processing method for each key value, the processing efficiency of the multi-key value command can be greatly improved.

[0084] In this embodiment, the electronic device can also determine the amount of data to be obtained each time, that is, the above-mentioned preset amount of data, before obtaining the data.

[0085] As an implementation manner, the electronic device can obtain the current remaining memory value and determine the preset amount of data according to the remaining memory value. It can be understood that the method of obtaining and sending the data corresponding to the key values while obtaining, and obtaining and sending the data in batches mainly considers the problem that the memory of the electronic device may be occupied by the obtained data more, resulting in a running crash. Therefore, the preset amount of data obtained each time can be determined according to the current remaining memory value of the electronic device.

[0086] In this embodiment, the electronic device determines a preset data volume according to the current remaining memory value, which may include: determining whether the remaining memory value is greater than a specified memory value; if the remaining memory value is greater than the specified memory value, using a first data volume as the preset data volume; if the remaining memory value is less than the specified memory value, using a second data volume as the preset data volume, and the second data volume is less than the first data volume.

[0087] Among them, the specified memory value can be used as a standard for judging whether the current memory usage of the electronic device occupies a large amount. If the remaining memory value is greater than the specified memory value, it means that the current remaining memory of the electronic device is relatively large. Therefore, a first data volume relatively larger than the second data volume can be selected as the preset data volume; if the remaining memory value is less than or equal to the specified memory value, it means that the current remaining memory of the electronic device is relatively small and its memory is relatively tight. Therefore, a second data volume relatively smaller than the first data volume can be used as the preset data volume.

[0088] Furthermore, both the above first data volume and the second data volume are less than the specified memory value. When determining the first data volume and the second data volume, the electronic device can, according to the remaining memory value, determine the memory that can be allocated when the remaining memory value is greater than the specified memory value, and calculate the ratio of the allocable memory to the number of threads corresponding to multiple second multi-key value commands, and use this ratio as the first data volume. The electronic device can also, according to the remaining memory value, determine the memory that can be allocated when the remaining memory value is less than or equal to the specified memory value, and calculate the ratio of the allocable memory to the number of threads corresponding to multiple second multi-key value commands, and use this ratio as the first data volume. It can be understood that the memory that can be allocated when the remaining memory value is greater than the specified memory value should be greater than the memory that can be allocated when the remaining memory value is less than or equal to the specified memory value. Therefore, the determined first data volume should be larger than the second data volume.

[0089] Of course, the first data volume and the second data volume can also be pre-set in the electronic device. In addition, the first data volume should meet the requirement that when the threads corresponding to multiple second multi-key value commands obtain data, the total data volume stored in the memory is less than the specified memory value; the second data volume should meet the requirement that when the threads corresponding to multiple second multi-key value commands obtain data, the total data volume stored in the memory is less than the remaining memory value.

[0090] In this embodiment, the electronic device determines a preset data volume according to the current remaining memory value, which may include: obtaining the preset data volume corresponding to the remaining memory value according to the pre-set correspondence between the memory value and the preset data volume. Among them, different memory values and the cache data volumes that can be supported can be determined in advance according to experiments to establish the correspondence between the memory value and the preset data volume. It should be noted that the preset data volumes determined according to this correspondence can all satisfy the normal operation of the programs in the electronic device.

[0091] In this embodiment, the preset data volume is determined by the memory value of the electronic device, so as to further ensure that the memory of the electronic device will not be occupied too much on the basis of avoiding the problem of excessive memory occupation when obtaining the data corresponding to each key value in batches for multiple key values, ensuring the normal operation of the electronic device.

[0092] In some embodiments, the electronic device may also obtain the ratio of the total data volume of the data corresponding to multiple key values and the specified acquisition times, and use the ratio as the preset data volume. It can be understood that a specified acquisition time can be set in the electronic device, and the specified acquisition time is the number of times each thread obtains data from the database. The setting of the specified acquisition time can meet the requirements of different scenarios and can also ensure that the number of data acquisitions will not be too large, resulting in too long overall data query time. The acquisition times can be set by the user or determined according to the current acquisition speed of the acquired data and the sending speed of the sending data.

[0093] Step S450: Repeat that each thread sends the acquired data to the service end after obtaining the data of the preset data volume according to the corresponding second most key value command until all the data corresponding to the multiple key values are sent to the service end.

[0094] In the embodiment of the present application, step S440 is repeated until all the data corresponding to the multiple key values are sent to the service end.

[0095] Thus, not only can multi-key value operations across hash slots be realized, grouping is carried out using different hash slots, reducing the read and write time for operating on a single key value in the related art, and using a multi-threaded technical solution to parallelly execute operations on multiple key values simultaneously, reducing the execution time and complexity of serial calls. In addition, the data of multiple key values is obtained and sent in batches, and the effect of pulling data and sending data simultaneously can be achieved, avoiding the problem of excessive memory occupation by the pulled data.

[0096] Please refer to Figure 5, which shows a structural block diagram of a multi-key-value command processing device 400 provided by an embodiment of the present application. The multi-key-value command processing device 400 is applied to the above-mentioned electronic device. The multi-key-value command processing device 400 includes: a hash slot determination module 410, a key-value grouping module 420, a command generation module 430, and a command execution module 440. Among them, the hash slot determination module 410 is configured to determine the hash slot corresponding to each key value among the multiple key values when a first multi-key-value command for the multiple key values is obtained; the key-value grouping module 420 is configured to, when the hash slots corresponding to the multiple key values include multiple hash slots, divide the multiple key values into multiple groups of key values according to the hash slot corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots; the command generation module 430 is configured to generate multiple second multi-key-value instructions according to each group of key values in the multiple groups of key values; the command execution module 440 is configured to execute the multiple second multi-key-value commands by using multiple threads, where the second multi-key-value commands executed by each thread among the multiple threads are different.

[0097] In some embodiments, the command execution module 440 may include: a thread allocation unit and a command sending unit. Among them, the thread allocation unit is configured to allocate each second multi-key-value command among the multiple second multi-key-value commands to one thread among the multiple threads, and the threads corresponding to each second multi-key-value command are different; the command sending unit is configured to each thread send the corresponding second multi-key-value command to the server.

[0098] In this embodiment, the thread allocation unit includes: a thread acquisition subunit and an allocation subunit. Among them, the thread acquisition subunit is configured to acquire available threads in the thread pool; the allocation subunit is configured to allocate each second multi-key-value command among the multiple second multi-key-value commands to one thread among the available threads.

[0099] In this manner, the allocation subunit may specifically be configured to: determine whether the number of available threads is less than the number corresponding to the multiple second multi-key-value commands; if the number of available threads is greater than or equal to the number corresponding to the multiple second multi-key-value commands, then allocate each second multi-key-value command among the multiple second multi-key-value commands to one thread among the available threads.

[0100] In this manner, the allocation subunit may also be configured to: if the number of available threads is less than the number corresponding to the multiple second multi-key-value commands, create a target number of threads in the thread pool, where the sum value of the target number and the number of available threads is greater than or equal to the number corresponding to the multiple second multi-key-value commands.

[0101] Further, the allocation subunit can also be used to: obtain the load rate of the processor before creating a target number of threads in the thread pool; if the load rate is less than the specified load rate, create a target number of threads in the thread pool.

[0102] In some embodiments, the hash slot determination module 410 can specifically be used to: calculate the hash slot corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm.

[0103] In this embodiment, the hash slot determination module 410 includes: a redundancy check unit and a remainder obtaining unit. Among them, the redundancy check unit is used to calculate the value corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm; the remainder obtaining unit is used to obtain the remainder of the value corresponding to each key value and the total number of hash slots corresponding to the database cluster, so as to obtain the number of the hash slot corresponding to each key value.

[0104] In some embodiments, the first multi-key value command is used to:

[0105] obtain the data corresponding to the multiple key values; or

[0106] set the key-value data pairs corresponding to the multiple key values; or

[0107] store the data corresponding to the multiple key values; or

[0108] delete the data corresponding to the multiple key values.

[0109] In some embodiments, when the first multi-key value command is used to obtain the data corresponding to the multiple key values, the processing device 400 of this multi-key value command may further include: a relationship establishment module and a data acquisition module. The relationship establishment module is used to establish the corresponding relationship between each key value among the multiple key values and each data according to the order of data input; the data acquisition module is used to obtain the data corresponding to each key value according to the corresponding relationship.

[0110] In some embodiments, when the first multi-key value command is used to obtain the data corresponding to the multiple key values, the command execution module 440 can specifically be used to: each thread sends the obtained data to the service end after obtaining a preset amount of data according to the corresponding second multi-key value command; repeat that each thread sends the obtained data to the service end after obtaining a preset amount of data according to the corresponding second multi-key value command until all the data corresponding to the multiple key values are sent to the service end.

[0111] In some embodiments, the command execution module 440 can also be used to: obtain the current remaining memory value; determine the preset data amount according to the remaining memory value.

[0112] In this embodiment, the command execution module 440 obtains the current remaining memory value; according to the remaining memory value, determining the preset data volume may include: determining whether the remaining memory value is greater than a specified memory value; if the remaining memory value is greater than the specified memory value, taking the first data volume as the preset data volume; if the remaining memory value is less than the specified memory value, taking the second data volume as the preset data volume, and the second data volume is less than the first data volume.

[0113] In some embodiments, the command execution module 440 may also be used to: obtain the ratio of the total data volume of the data corresponding to the multiple key values to the specified number of acquisition times according to the total data volume of the data corresponding to the multiple key values and the specified number of acquisition times, and take the ratio as the preset data volume.

[0114] In some embodiments, the command execution module 440 may also be used to: when the hash slots corresponding to the multiple key values include one hash slot, execute the first multi-key value command.

[0115] In some embodiments, the first multi-key value command is a command for a Redis database cluster.

[0116] Those skilled in the art can clearly understand that for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the foregoing method embodiments, and will not be elaborated herein.

[0117] In several embodiments provided in the present application, the coupling between modules may be electrical, mechanical, or other forms of coupling. Additionally, in each embodiment of the present application, the various functional modules may be integrated in one processing module, or each module may exist physically alone, or two or more modules may be integrated in one module. The above-mentioned integrated modules may be implemented in the form of hardware or in the form of software functional modules.

[0118] In summary, for the solution provided in this application, when a first multi-key value command for multiple key values is obtained, the hash slots corresponding to each key value in the multiple key values are determined. When the hash slots corresponding to the multiple key values include multiple hash slots, the multiple key values are divided into multiple groups of key values according to the hash slots corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots. Multiple second multi-key value instructions are generated according to each group of key values in the multiple groups of key values, and multiple threads are used to execute the multiple second multi-key value commands, where the second multi-key value commands executed by each thread in the multiple threads are different. Therefore, when processing a multi-key value command across hash slots, grouping can be performed through the hash slots corresponding to the key values, and then the multi-key value commands can be executed in parallel by different threads according to the grouping, improving the execution efficiency of the multi-key value command across hash slots, and further improving the efficiency when operating on the database.

[0119] Please refer to Figure 6 , which shows a structural block diagram of an electronic device provided in an embodiment of this application. The electronic device 100 may be an electronic device such as a mobile terminal, a tablet computer, a notebook computer, a PC, or a server that can run application programs. The electronic device 100 in this application may include one or more of the following components: a processor 110, a memory 120, and one or more application programs, where one or more application programs may be stored in the memory 120 and configured to be executed by one or more processors 110, and one or more programs are configured to execute the method described in the foregoing method embodiments.

[0120] The processor 110 may include one or more processing cores. The processor 110 connects various parts within the entire electronic device 100 using various interfaces and circuits. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 120, and by invoking data stored in the memory 120, it performs various functions of the electronic device 100 and processes data. Optionally, the processor 110 may be implemented in at least one hardware form of digital signal processing (DSP), field-programmable gate array (FPGA), or programmable logic array (PLA). The processor 110 may integrate a combination of one or several of a central processing unit (CPU), a graphics processing unit (GPU), and a modem, etc. Among them, the CPU mainly processes the operating system, user interface, application programs, etc.; the GPU is responsible for rendering and drawing display content; the modem is used to process wireless communications. It can be understood that the above-mentioned modem may not be integrated into the processor 110 and may be implemented separately through a communication chip.

[0121] The memory 120 may include random access memory (RAM) and may also include read-only memory. The memory 120 can be used to store instructions, programs, code, code sets, or instruction sets. The memory 120 may include a program storage area and a data storage area. Among them, the program storage area can store instructions for implementing the operating system, instructions for implementing at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the following various method embodiments, etc. The data storage area can also store data created during the use of the electronic device 100 (such as phone books, audio and video data, chat record data), etc.

[0122] Please refer to Figure 7, which shows a structural block diagram of a computer-readable storage medium provided by an embodiment of the present application. Program code is stored in the computer-readable medium 800, and the program code can be called by a processor to execute the methods described in the above method embodiments. The computer-readable storage medium 800 can be an electronic memory such as a flash memory, EEPROM (electrically erasable programmable read-only memory), EPROM, hard disk, or ROM. Optionally, the computer-readable storage medium 800 includes a non-transitory computer-readable storage medium. The computer-readable storage medium 800 has a storage space for the program code 810 that executes any method step in the above methods. These program codes can be read out from or written into one or more computer program products. The program code 810 can be compressed in an appropriate form, for example.

[0123] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, and are not intended to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for processing multi-key value commands, characterized in that, The method includes: When a first multi-key value command for multiple key values is obtained, determining hash slots corresponding to each key value among the multiple key values, where the first multi-key value command is a command for a Redis database cluster; When the hash slots corresponding to the multiple key values include multiple hash slots, dividing the multiple key values into multiple groups of key values according to the hash slots corresponding to each key value, where the multiple groups of key values correspond one-to-one to the multiple hash slots; Generating a second multi-key value command corresponding to each group of key values according to each group of key values in the multiple groups of key values, according to the type of the first multi-key value command corresponding to each group of key values, and the command content for the key values in each group of key values, to obtain multiple second multi-key value instructions; Using multiple threads to execute the multiple second multi-key value commands, where different second multi-key value commands are executed by each thread among the multiple threads.

2. The method according to claim 1, wherein The using multiple threads to execute the multiple second multi-key value commands includes: Allocating each second multi-key value command among the multiple second multi-key value commands to one thread among the multiple threads, where different threads correspond to different second multi-key value commands; Each thread sends the corresponding second multi-key value command to the server.

3. The method according to claim 2, characterized in that, The allocating each second multi-key value command among the multiple second multi-key value commands to one thread among the multiple threads includes: Obtaining available threads in the thread pool; Allocating each second multi-key value command among the multiple second multi-key value commands to one of the available threads.

4. The method according to claim 3, characterized in that The allocating each second multi-key value command among the multiple second multi-key value commands to one of the available threads includes: Judging whether the number of available threads is less than the number corresponding to the multiple second multi-key value commands; If the number of available threads is greater than or equal to the number corresponding to the multiple second multi-key value commands, then allocating each second multi-key value command among the multiple second multi-key value commands to one of the available threads.

5. The method according to claim 4, characterized in that, The allocating each second multi-key value command among the multiple second multi-key value commands to one of the available threads further includes: If the number of available threads is less than the number corresponding to the multiple second multi-key value commands, creating a target number of threads in the thread pool, where the sum of the target number and the number of available threads is greater than or equal to the number corresponding to the multiple second multi-key value commands.

6. The method according to claim 5, characterized in that, Before creating the target number of threads in the thread pool, the method further includes: Obtaining the load rate of the processor; If the load rate is less than the specified load rate, creating a target number of threads in the thread pool.

7. The method according to any one of claims 1-6, characterized in that, The determining hash slots corresponding to each key value among the multiple key values includes: Calculating hash slots corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm.

8. The method according to claim 7, characterized in that The calculating hash slots corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm includes: Calculating a numerical value corresponding to each key value among the multiple key values through a cyclic redundancy check algorithm; Obtaining the remainder of the numerical value corresponding to each key value and the total number of hash slots corresponding to the database cluster, to obtain the number of the hash slot corresponding to each key value.

9. The method according to any one of claims 1-6, characterized in that, The first multi-key-value command is used for: Obtaining data corresponding to the multiple key values; or Setting key-value data pairs corresponding to the multiple key values; or Storing data corresponding to the multiple key values; Or Deleting data corresponding to the multiple key values.

10. The method according to claim 9, characterized in that When the first multi-key-value command is used to obtain data corresponding to the multiple key values, after executing the multiple second multi-key-value commands using multiple threads, the method further includes: Merging the obtained data according to the order of data input, to obtain data corresponding to each key value among the multiple key values.

11. The method according to claim 10, characterized in that, The merging the obtained data according to the order of data input, to obtain data corresponding to each key value among the multiple key values, includes: Establishing a corresponding relationship between each key value among the multiple key values and each piece of data according to the order of data input; Obtaining data corresponding to each key value according to the corresponding relationship.

12. The method according to claim 9, wherein When the first multi-key-value command is used to obtain data corresponding to the multiple key values, the executing the multiple second multi-key-value commands using multiple threads includes: Each thread, according to the corresponding second multi-key-value command, after obtaining a preset amount of data, sends the obtained data to the service end; Repeating that each thread, according to the corresponding second multi-key-value command, after obtaining a preset amount of data, sends the obtained data to the service end, until all data corresponding to the multiple key values are sent to the service end.

13. The method according to claim 12, characterized in that, The each thread, according to the corresponding second multi-key-value command, after obtaining a preset amount of data, sending the obtained data to the service end, further includes: Obtaining the current remaining memory value; Determining the preset amount of data according to the remaining memory value.

14. The method according to claim 13, wherein The determining the preset amount of data according to the remaining memory value includes: Judging whether the remaining memory value is greater than a specified memory value; If the remaining memory value is greater than the specified memory value, taking a first amount of data as the preset amount of data; If the remaining memory value is less than the specified memory value, taking a second amount of data as the preset amount of data, the second amount of data being less than the first amount of data.

15. The method according to claim 12, wherein The each thread, according to the corresponding second multi-key-value command, after obtaining a preset amount of data, sending the obtained data to the service end, further includes: Obtaining a ratio of the total amount of data corresponding to the multiple key values to a specified number of acquisition times, and taking the ratio as the preset amount of data.

16. The method according to any one of claims 1-6, characterized in that, After determining the hash slots corresponding to each key value among the multiple key values, the method further includes: When the hash slots corresponding to the multiple key values include one hash slot, executing the first multi-key-value command.

17. A processing device for multi-key-value commands, characterized in that, The device includes: a hash slot determination module, a key value grouping module, a command generation module, and a command execution module, where The hash slot determination module is used to determine the hash slots corresponding to each key value among the multiple key values when obtaining a first multi-key-value command for multiple key values, and the first multi-key-value command is a command for a Redis database cluster; The key-value grouping module is used to divide the multiple key-values into multiple groups of key-values according to the hash slots corresponding to each key-value when the hash slots corresponding to the multiple key-values include multiple hash slots, wherein the multiple groups of key-values correspond one-to-one to the multiple hash slots; The command generation module is used to generate a second multi-key-value command corresponding to each group of key-values in the multiple groups of key-values according to the type of the first multi-key-value command corresponding to each group of key-values and the command content for the key-values in each group of key-values, and obtain multiple second multi-key-value instructions; The command execution module is used to execute the multiple second multi-key-value commands by using multiple threads, wherein the second multi-key-value commands executed by each thread in the multiple threads are different.

18. An electronic device, characterized in that, Comprising: One or more processors; A memory; One or more applications, wherein the one or more applications are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs are configured to execute the method according to any one of claims 1-16.

19. A computer-readable storage medium, characterized in that, Program code is stored in the computer-readable storage medium, and the program code can be called by a processor to execute the method according to any one of claims 1-16.

Citation Information

Patent Citations

  • Data analysis method, device and system of database

    CN104679884A

  • Data query device and method based on redis cluster

    CN105159985A