Data loading method and device for Redis service, electronic equipment and storage medium

By using alternate arrays to load data and migrating data structures in Redis service, the problem of service capability degradation when the Redis service loads data files is solved, and the balance between data loading and event processing is achieved, ensuring the stability of the service.

CN119045916APending Publication Date: 2024-11-29BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411268842.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-10
Publication Date
2024-11-29

AI Technical Summary

Technical Problem

The Redis service will cause a decline in service capabilities when loading data files, mainly because the main thread needs to intermittently process IO events and module events to prevent service interruption, which will affect the data loading speed.

Method used

When the main thread determines that the Redis database has no rehash state, it uses a background thread to load the target data into the alternate array, and after the data is fully loaded, the main thread migrates the original main array and the alternate array data to form a new main array. This enables data loading while maintaining service stability.

Benefits of technology

It effectively solves the problem of service capability degradation when the Redis service loads data files, ensures that events can still be processed stably when loading data, and improves the service's response capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045916A_ABST
    Figure CN119045916A_ABST
Patent Text Reader

Abstract

The invention provides a Redis service data loading method and device, electronic equipment and a storage medium, and the method comprises the steps that a main thread of a Redis service receives target data needing to be loaded into a memory; under the condition that the main thread determines that each Redis database does not have a re-hash state, a background thread of the Redis service analyzes the target data and loads the analyzed data into a standby array; and when it is determined that the target data is completely loaded to the standby array, the main thread obtains a new main array containing the data in the original main array and the data in the standby array through migration operation, and loading of the target data is completed. According to the method and the device, the problem that the service capability is reduced when the data file is loaded by the Redis service in the related technology is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a method and device for loading data into a Redis service, an electronic device, and a storage medium. Background Art

[0002] As a single-threaded in-memory KV (key-value) database service, Redis is widely used in Internet cache services. The main advantages of Redis services are rich data types, low latency, and high performance, which can meet various high-concurrency scenarios. Redis services support two data persistence formats, one is RDB format and the other is aof format. Data loading is generally loading files in aof format or RDB format.

[0003] In the related art, when the main thread of the Redis service loads the RDB file in a blocking manner to load the data into the memory, it will intermittently process IO events and module events to prevent external requests from thinking that the Redis service has been interrupted. Of course, this intermittent processing of IO events and module events will also lead to a decrease in service capabilities.

[0004] Therefore, there is a problem in the related art that the service capability of the Redis service decreases when loading data files. Summary of the invention

[0005] The present application provides a method and device for loading data by a Redis service, an electronic device, and a storage medium, so as to at least solve the problem of reduced service capability when a Redis service loads data files in the related art.

[0006] According to one aspect of an embodiment of the present application, a method for loading data in a Redis service is provided, comprising:

[0007] The main thread of the Redis service receives the target data that needs to be loaded into memory;

[0008] When the main thread determines that each Redis database does not have a rehashing state, the background thread of the Redis service parses the target data and loads the parsed data into the backup array;

[0009] When it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes the loading of the target data.

[0010] Optionally, as in the aforementioned method, the main thread determines that each Redis database does not exist in a rehashing state, including:

[0011] The main thread determines a first current state of the dict dictionary table of the Redis database and a second current state of the expire dictionary table;

[0012] When the main thread determines that neither the first current state nor the second current state exists in a rehashed state, the main thread determines that the Redis database does not exist in a rehashed state.

[0013] Optionally, as in the aforementioned method, after the main thread determines that each Redis database does not have a rehashing state, the method further includes:

[0014] The main thread turns off the rehashing function of the Redis database so that the main thread cannot cause the Redis database to enter a rehashing state.

[0015] Optionally, as in the aforementioned method, the method further comprises:

[0016] When the main thread determines that each Redis database is in a rehashing state, the main thread parses the target data and loads the parsed data into the original main array and the valid array in the backup array.

[0017] Optionally, as in the aforementioned method, the background thread of the Redis service parses the target data and loads the parsed data into a spare array, including:

[0018] The background thread initialization determines the initialization slot value according to the auxiliary information of the target data;

[0019] Based on the initialization slot value, obtain the spare array containing the number of slots of the initialization slot number value;

[0020] The target data is parsed, and the parsed data is loaded into a spare array.

[0021] Optionally, as in the aforementioned method, the parsed data is loaded into a spare array, including:

[0022] In a case where the data block of the target data is a first data block of an auxiliary field type, performing value assignment processing on the first data block to store the first data block in the spare array;

[0023] In a case where the data block of the target data is a second data block of a key-value pair field type, the second data block is stored in the backup array by inserting the second data block into a corresponding Redis data structure.

[0024] Optionally, as in the aforementioned method, the main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes loading of the target data, including:

[0025] The main thread enters a rehashing state, migrates the data in the original main array to the backup array, and identifies the backup array as a new main array.

[0026] According to another aspect of an embodiment of the present application, a device for loading data by a Redis service is also provided, including:

[0027] The receiving module is used to enable the main thread of the Redis service to receive the target data that needs to be loaded into the memory;

[0028] A loading module, configured to parse the target data and load the parsed data into a backup array when the main thread determines that each Redis database does not have a rehashing state;

[0029] The identification module is used to identify the spare array as a main array through the main thread and complete the loading of the target data when it is determined that the target data is completely loaded into the spare array.

[0030] According to another aspect of the embodiments of the present application, there is also provided an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus; wherein the memory is used to store a computer program; and the processor is used to execute the method steps in any of the above embodiments by running the computer program stored in the memory.

[0031] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the method steps in any of the above embodiments when executed.

[0032] In an embodiment of the present application, a backup array is used to load data. When the main thread determines that there is no rehashing state in each Redis database, the background thread of the Redis service parses the target data and loads the parsed data into the backup array. Since the target data is loaded through the backup array, the original main array can still be used to process events; and when it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array containing the data in the main array and the data in the backup array through a migration operation, so that the loading of the target data can be achieved while the service capability is guaranteed through the original main array, thereby achieving the technical effect of stabilizing the service capability when the Redis service loads data files, thereby solving the problem of reduced service capability when the Redis service loads data files in the related art. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0034] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0035] Figure 1 It is a schematic diagram of a hardware environment of an optional method for loading data with a Redis service according to an embodiment of the present application;

[0036] Figure 2 It is a flowchart of an optional method for loading data using a Redis service according to an embodiment of the present application;

[0037] Figure 3 It is a flowchart of another optional method for loading data using a Redis service according to an embodiment of the present application;

[0038] Figure 4 It is a flowchart of another optional method for loading data using a Redis service according to an embodiment of the present application;

[0039] Figure 5 It is a structural block diagram of an optional device for loading data from a Redis service according to an embodiment of the present application;

[0040] Figure 6 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0041] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0042] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0043] In the related art, the main thread of the Redis service will intermittently process IO events (mainly involving data transmission between the client and Redis, including receiving client commands, sending responses, etc.) and module events (events triggered by Redis modules, which can extend the functions of Redis) during the process of blocking loading of RDB files to prevent external requests from thinking that the Redis service has been interrupted. This ensures that the Redis service can still process client requests when loading data, which specifically includes the following steps:

[0044] 1. The main thread loads data in a blocking manner.

[0045] 2. The main thread processes events intermittently: (1). Loading data: The main thread reads the RDB file and inserts the key-value pairs into tmpht; (2). Checking events: The main thread periodically checks whether there are pending IO events and module events; (3). Processing events: The main thread processes IO events such as client connection requests, reads client commands, sends responses, and processes events triggered by Redis custom modules; (4). Continue loading: After processing the event, the main thread continues to load data from the RDB file; (5). Repeat the above steps: The main thread repeats the steps of loading data, checking events, and processing events until all data is loaded.

[0046] Using this method for Redis service can reduce service interruption time: by intermittently processing IO events and module events, the interruption time of Redis service can be reduced, the service availability can be improved, and the service response can be ensured: even in the process of loading data, the Redis service can respond to the client's request. However, since the main thread of the Redis service needs to process events intermittently, the speed of loading data will be affected, the service level may be reduced, and further, frequent task switching may increase CPU and memory consumption.

[0047] It can be seen that by intermittently processing IO events and module events during the main thread's blocking loading of RDB files, the Redis service can maintain response to external requests and reduce service interruption time while loading data, but it may also lead to a decline in service level.

[0048] In order to overcome the above technical problems existing in the related art, according to one aspect of the embodiment of the present application, a method for loading data from a Redis service is provided. Optionally, in this embodiment, the above method for loading data from a Redis service can be applied to Figure 1 In the hardware environment composed of terminal 1402 and server 1404 shown in FIG. Figure 1 As shown, server 1404 is connected to terminal 1402 via a network, and can be used to provide services (such as game services, application services, etc.) for the terminal or a client installed on the terminal. A database can be set up on the server or independently of the server to provide data storage services for server 1404.

[0049] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal may not be limited to a PC, a mobile phone, a tablet computer, etc.

[0050] The method for loading data by the Redis service of the embodiment of the present application can be executed by the server, or by the terminal, or by both the server and the terminal. The method for loading data by the Redis service of the embodiment of the present application can also be executed by the client installed thereon.

[0051] Taking the method of loading data by the Redis service in this embodiment executed by the server as an example, Figure 2 A method for loading data into a Redis service provided in an embodiment of the present application includes the following steps:

[0052] Step S202: The main thread of the Redis service receives target data that needs to be loaded into the memory.

[0053] The method for loading data with the Redis service in this embodiment can be applied to scenarios of Internet cache services, for example, a scenario of loading data from a persistently stored database.

[0054] In the process of restarting Redis or restoring data from RDB files or aof files, the main thread of the Redis service will receive the target data that needs to be loaded into the memory. In other words, the target data is the data that needs to be read from the database in the persistent storage. Because Redis is an in-memory database, all data is operated in the memory, so the target data needs to be loaded into the memory so that Redis can quickly respond to client requests, because the memory access speed is much higher than the disk access speed.

[0055] Step S204, when the main thread determines that each Redis database does not have a re-hashing state, the background thread of the Redis service parses the target data and loads the parsed data into the backup array.

[0056] After the main thread determines that the target data needs to be loaded into the memory, it can check each Redis database to determine whether there is a rehashing state. The Redis database is the core data structure of Redis, which uses a hash table to store key-value pairs. The rehashing state is the rehash state. When the Redis database (i.e., RedisDB) is in the rehash state, it means that the Redis database is gradually migrating the data in the old hash table to the new hash table.

[0057] As an optional implementation, the main thread in the aforementioned step S204 can determine that each Redis database does not have a rehashed state by the following steps: the main thread determines the first current state of the dict dictionary table of the Redis database and the second current state of the expire dictionary table; when the main thread determines that the first current state and the second current state do not have a rehashed state, it determines that the Redis database does not have a rehashed state. That is to say, in general, the dictionary table used by the Redis database to store key-value pairs includes a dict dictionary table and an expire dictionary table, so that for each Redis database, the first current state of its corresponding dict dictionary table and the second current state of the expire dictionary table can be determined, the first current state is used to indicate whether the dict dictionary table is in a rehashed state. The state information, the second current state is used to indicate whether the expire dictionary table is in a rehashed state. After determining the first current state and the second current state, the main thread can determine whether the first current state and the second current state are both rehashed states, and when it is determined that the first current state and the second current state do not have a rehashed state, it is determined that the Redis database does not have a rehashed state. When it is determined that the dict dictionary table and the expire dictionary table do not have a rehashed process. The dict dictionary table is a general hash table implementation in Redis. The expire dictionary table is a special dict instance used to store the expiration time of the key. In other words, the key value of Redis also has an attribute that is whether it expires in a certain number of seconds and will be deleted. This is implemented by the expire dictionary table.

[0058] When the main thread determines through the above method that each Redis database does not exist in the rehashing state, it means that there is currently no migration between different arrays (i.e., hash tables). Therefore, in order to avoid the rehashing function in the later stage, which causes a certain ht_table to be occupied during the asynchronous loading process and cause failure. The main thread can turn off the rehashing function of the Redis database so that the main thread cannot put the Redis database into the rehashing state. Optionally, the rehashing function can be turned off by including but not limited to the following methods: Adjust the maximum load factor: You can control when the hash table starts to rehash by adjusting the maximum load factor (maxfill). This can be achieved by setting a lower maximum load factor when creating the hash table in the client code.

[0059] When the main thread determines that there is no rehashing state in each Redis database, therefore, the array is not occupied by the rehashing function. In this case, this embodiment parses the target data through the background thread of the Redis service and loads the parsed data into the backup array.

[0060] like Figure 3 and Figure 4 As shown, as an optional implementation, the background thread of the Redis service in the aforementioned step S204 can parse the target data and load the parsed data into the backup array through the following steps S302 to S306:

[0061] Step S302, the background thread initialization determines the initialization slot value according to the auxiliary information of the target data. Optionally, the background thread can initialize several objects required for loading. For example, one of the objects can calculate the initialization slot value according to the auxiliary information of the target data. The auxiliary information can be obtained from the header of the file, and the number of keys in the file can be obtained from the auxiliary information, so as to evaluate the initialization slot value of the backup array. Too large a slot number will be a waste, and too small a slot number will cause the hash to insert data slowly, and after the final loading is completed, the rehashing function is turned on. In addition, since the implementation process of the rehashing function between the two arrays is relatively long, the initialization slot value is expanded in place at one time, and the expansion formula is as follows:

[0062] 2*E(log2(ht_table[0].size+aux.size) / 2+1)).

[0063] Among them, ht_table[0].size indicates the size of the original main array, aux.size indicates the size of the current backup array, E(x) indicates rounding up to the nearest integer, log2(x) indicates the logarithm with base 2, and the log2 and E functions in the formula are used to calculate a suitable exponent so that the size of the newly obtained backup array is at least twice the sum of the sizes of the original main array and the current backup array.

[0064] Step S304, based on the initialization slot value, a spare array including the number of slots of the initialization slot value is obtained. After the initialization slot value is determined, a spare array including the number of slots of the initialization slot value can be obtained.

[0065] Step S306, parse the target data and load the parsed data into the spare array.

[0066] After obtaining the target data and the backup array, the target data can be parsed, and then the parsed data can be loaded into the backup array. Since in Redis, the process of reading the content type and processing it usually involves parsing and storing different types of data. Therefore, it can be processed according to the type of the read data block. As an optional implementation, the relevant operations of loading the parsed data into the backup array can be implemented through the following steps: when the data block of the target data is the first data block of the auxiliary field type, the first data block is assigned to the first data block to store the first data block in the backup array; when the data block of the target data is the second data block of the key-value pair field type, the second data block is inserted into the corresponding Redis data structure to store the second data block in the backup array. When Redis loads data from target data of the type of RDB file, it reads the file content in a certain format. The target data usually contains multiple data blocks, each of which represents a key-value pair or a group of related data. The data block may also contain auxiliary information of auxiliary field type, such as expiration time. The first data block of auxiliary field type usually refers to additional information related to the key-value pair. When Redis reads this kind of information, it will set the corresponding attributes according to this information and implement the assignment processing of the first data block. For example, suppose the following content is read from the RDB file:

[0067] type:string

[0068] key:mykey

[0069] value:hello

[0070] expire:60

[0071] The expire field here is of auxiliary field type, indicating that the expiration time of the key mykey is 60 seconds. The processing steps are as follows: 1. Parse type: confirm that the type is string. 2. Read key-value pairs: read key and value. 3. Process auxiliary fields: read the expire field and set the expiration time.

[0072] In the case where the data block of the target data is the second data block of the key-value pair field type, for the key-value pair field, Redis needs to insert these key-value pairs into the appropriate data structure. For example, suppose the following content is read from the RDB file:

[0073] type:hash

[0074] key:myhash

[0075] field1:value1

[0076] field2:value2

[0077] The above myhash is a key of a key-value pair field type, which contains two fields field1 and field2. The processing steps are as follows: 1. Parse the type: Confirm that the type is hash. 2. Read the key-value pair: Read the key. 3. Insert the key-value pair: According to the type, insert the key-value pair into the appropriate Redis data structure.

[0078] Furthermore, in the above-mentioned Redis service process, checksum processing (i.e., checksum to verify data integrity) is also performed. By performing this checksum processing, when the Redis service recovers data from target data such as RDB files, it can calculate the checksum of the RDB file and compare it with the checksum in the RDB file header to ensure that the file is not damaged. Specifically, when creating a snapshot file of the target data, the Redis service calculates the checksum of the entire target data and writes the checksum to the file header of the snapshot file of the target data; when the Redis service recovers data from the target data, it calculates the checksum of the file again and compares it with the checksum in the above-mentioned file header; if the checksum does not match, the Redis service will report an error and may refuse to load the file.

[0079] Step S206, when it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes the loading of the target data.

[0080] After determining that the target data is completely loaded into the backup array, as an optional implementation method, as in the aforementioned method, the main thread can obtain a new main array containing the data in the original main array and the data in the backup array through a migration operation through the following steps, and complete the loading of the target data: the main thread enters a rehashing state, migrates the data in the original main array to the backup array, and identifies the backup array as the new main array. That is, when the main thread of the Redis service enters a rehashing state, it will gradually migrate the data in the original main array to the backup array. The main thread can read the key-value pairs in the original main array, and then insert the read key-value pairs into the backup array. The main thread repeats the above reading and inserting steps until all the key-value pairs in the original main array are migrated to the backup array, and finally the backup array is identified as the new main array. At this point, the loading of the target data can be completed.

[0081] As an optional implementation, as the aforementioned method, the method also includes the following steps: when the main thread determines that each Redis database is in a rehashing state, the main thread parses the target data and loads the parsed data into the valid arrays in the original main array and the backup array. Specifically, during the loading process, the main thread needs to check whether each Redis database is in a rehashing state. If a Redis database is being rehashed, this means that there are two arrays (i.e., the original main array and the backup array), namely: the old hash table and the new hash table. In this case, the main thread needs to determine which array in the original main array and the backup array is currently valid, and load the data into the valid array. The main thread loads the parsed data into the valid array.

[0082] In an embodiment of the present application, a backup array is used to load data. When the main thread determines that there is no rehashing state in each Redis database, the background thread of the Redis service parses the target data and loads the parsed data into the backup array. Since the target data is loaded through the backup array, the original main array can still be used to process events; and when it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array containing the data in the main array and the data in the backup array through a migration operation, so that the loading of the target data can be achieved while the service capability is guaranteed through the original main array, thereby achieving the technical effect of stabilizing the service capability when the Redis service loads data files, thereby solving the problem of reduced service capability when the Redis service loads data files in the related art.

[0083] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.

[0084] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0085] According to another aspect of an embodiment of the present application, a device for loading data via a Redis service for implementing the above-mentioned method for loading data via a Redis service is also provided. Figure 5 is a structural block diagram of an optional device for loading data from a Redis service according to an embodiment of the present application, such as Figure 5 As shown, the device may include:

[0086] According to another aspect of an embodiment of the present application, a device for loading data by a Redis service is also provided, including:

[0087] A receiving module 51 is used to enable the main thread of the Redis service to receive target data that needs to be loaded into the memory;

[0088] A loading module 52, configured to, when the main thread determines that each Redis database does not have a rehashing state, parse the target data by the background thread of the Redis service, and load the parsed data into a spare array;

[0089] The identification module 53 is used to identify the spare array as a main array through the main thread and complete the loading of the target data when it is determined that the target data is completely loaded into the spare array.

[0090] It should be noted that the receiving module 51 in this embodiment can be used to execute the above step S202, the loading module 52 in this embodiment can be used to execute the above step S204, and the identification module 53 in this embodiment can be used to execute the above step S206.

[0091] Through the above module, a backup array is used to load data. When the main thread determines that each Redis database does not exist in a rehashing state, the background thread of the Redis service parses the target data and loads the parsed data into the backup array. Since the target data is loaded through the backup array, the original main array can still be used to process events; and when it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array containing the data in the main array and the data in the backup array through a migration operation, so that the original main array can be used to ensure the service capability on the basis of realizing the loading of the target data, thereby achieving the technical effect of stabilizing the service capability when the Redis service loads data files, thereby solving the problem of reduced service capability when the Redis service loads data files in the related art.

[0092] As an optional embodiment, as in the aforementioned device, the loading module 52 is configured as follows:

[0093] The main thread determines the first current state of the dict dictionary table of the Redis database and the second current state of the expire dictionary table;

[0094] When it is determined that neither the first current state nor the second current state has a rehashed state, the main thread determines that the Redis database does not have a rehashed state.

[0095] As an optional embodiment, the aforementioned device further includes a closing module, wherein the closing module is used to:

[0096] The main thread turns off the rehashing function of the Redis database so that the main thread cannot put the Redis database into a rehashing state.

[0097] As an optional embodiment, the aforementioned device further includes a parsing module, wherein the parsing module is used to:

[0098] When the main thread determines that each Redis database is in a rehashing state, the main thread parses the target data and loads the parsed data into the valid arrays in the original main array and the backup array.

[0099] As an optional embodiment, as in the aforementioned device, the loading module 52 includes:

[0100] An initialization unit, used for background thread initialization to determine the initialization slot value according to the auxiliary information of the target data;

[0101] A spare array determination unit, used for obtaining a spare array of the number of slots including the initialization slot number value based on the initialization slot number value;

[0102] The parsing unit is used to parse the target data and load the parsed data into the spare array.

[0103] As an optional embodiment, in the aforementioned device, the parsing unit is configured as follows:

[0104] In the case where the data block of the target data is a first data block of the auxiliary field type, performing assignment processing on the first data block to store the first data block in the spare array;

[0105] In the case where the data block of the target data is a second data block of a key-value pair field type, the second data block is stored in the backup array by inserting the second data block into a corresponding Redis data structure.

[0106] As an optional embodiment, as in the aforementioned device, the identification module 53 is configured as follows:

[0107] The main thread enters the rehashing state, migrates the data in the original main array to the backup array, and identifies the backup array as the new main array.

[0108] The device in this embodiment, in addition to the above modules, may also include a module for executing any method in any of the embodiments of the method for loading data via a Redis service as described above.

[0109] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.

[0110] According to another aspect of an embodiment of the present application, an electronic device for implementing the above-mentioned method of loading data by a Redis service is also provided. The electronic device may be a server, a terminal, or a combination thereof.

[0111] According to another embodiment of the present application, there is also provided an electronic device, including: Figure 6 As shown, the electronic device may include: a processor 1501 , a communication interface 1502 , a memory 1503 and a communication bus 1504 , wherein the processor 1501 , the communication interface 1502 , and the memory 1503 communicate with each other via the communication bus 1504 .

[0112] Memory 1503, used for storing computer programs;

[0113] The processor 1501 is used to implement the following steps when executing the program stored in the memory 1503:

[0114] Step S202: The main thread of the Redis service receives target data that needs to be loaded into the memory.

[0115] Step S204, when the main thread determines that each Redis database does not have a re-hashing state, the background thread of the Redis service parses the target data and loads the parsed data into the backup array.

[0116] Step S206, when it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes the loading of the target data.

[0117] Optionally, in this embodiment, the above-mentioned communication bus can be a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The communication interface is used for communication between the above-mentioned electronic device and other devices.

[0118] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0119] As an example, the memory 1503 may include, but is not limited to, the receiving module 51, the loading module 52, and the identification module 53 in the device for loading data from the Redis service. In addition, other module units in the device for loading data from the Redis service may also be included but are not limited to, which will not be described in detail in this example.

[0120] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0121] An embodiment of the present application further provides a computer-readable storage medium, the storage medium including a stored program, wherein the method steps of the above method embodiment are executed when the program is run.

[0122] Optionally, in this embodiment, the storage medium may include but is not limited to: a U disk, a ROM, a RAM, a mobile hard disk, a magnetic disk or an optical disk, and other media that can store program codes.

[0123] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.

[0124] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.

[0125] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.

[0126] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0127] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.

[0128] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0129] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.

Claims

1. A method for loading data in a Redis service, characterized in that: include: The main thread of the Redis service receives the target data that needs to be loaded into memory; When the main thread determines that each Redis database does not have a rehashing state, the background thread of the Redis service parses the target data and loads the parsed data into the backup array; When it is determined that the target data is completely loaded into the backup array, the main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes the loading of the target data.

2. The method according to claim 1, characterized in that The main thread determines that each Redis database does not have a rehashing state, including: The main thread determines a first current state of the dict dictionary table of the Redis database and a second current state of the expire dictionary table; When the main thread determines that neither the first current state nor the second current state exists in a rehashed state, the main thread determines that the Redis database does not exist in a rehashed state.

3. The method according to claim 2, characterized in that After the main thread determines that each Redis database does not have a rehashing state, the method further includes: The main thread turns off the rehashing function of the Redis database so that the Redis database cannot enter the rehashing state.

4. The method according to claim 1, characterized in that: The method further comprises: When the main thread determines that each Redis database is in a rehashing state, the main thread parses the target data and loads the parsed data into the original main array and the valid array in the backup array.

5. The method according to claim 1, characterized in that: The background thread of the Redis service parses the target data and loads the parsed data into a spare array, including: The background thread initialization determines the initialization slot value according to the auxiliary information of the target data; Based on the initialization slot value, obtain the spare array containing the number of slots of the initialization slot number value; The target data is parsed, and the parsed data is loaded into a spare array.

6. The method according to claim 1, characterized in that The parsed data is loaded into a spare array, including: In a case where the data block of the target data is a first data block of an auxiliary field type, performing assignment processing on the first data block to store the first data block in the spare array; In a case where the data block of the target data is a second data block of a key-value pair field type, the second data block is stored in the backup array by inserting the second data block into a corresponding Redis data structure.

7. The method according to any one of claims 1 to 6, characterized in that The main thread obtains a new main array including the data in the original main array and the data in the backup array through a migration operation, and completes loading of the target data, including: The main thread enters a rehashing state, migrates the data in the original main array to the backup array, and identifies the backup array as a new main array.

8. A device for loading data in a Redis service, characterized in that: include: The receiving module is used to enable the main thread of the Redis service to receive the target data that needs to be loaded into the memory; A loading module, configured to parse the target data and load the parsed data into a backup array when the main thread determines that each Redis database does not have a rehashing state; The identification module is used to identify the spare array as a main array through the main thread and complete the loading of the target data when it is determined that the target data is completely loaded into the spare array.

9. An electronic device comprising a processor, a communication interface, a memory and a communication bus, wherein: The processor, the communication interface and the memory communicate with each other via the communication bus, wherein: The memory is used to store computer programs; The processor is configured to execute the method according to any one of claims 1 to 7 by running the computer program stored in the memory.

10. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.