A data timeout management method, apparatus, electronic device, and readable storage medium

By creating a first string in Redis to set a timeout for hash type fields, the problem of poor timeout management in existing technologies is solved, achieving effective field management and efficient timeout setting.

CN116910053BActive Publication Date: 2025-10-31CHINA MOBILE M2M +1
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202211632193.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-19
Publication Date
2025-10-31
Estimated Expiration
2042-12-19

AI Technical Summary

Technical Problem

In existing technologies, Redis has poor timeout management for hash types and cannot set an expiration time for each field in a hash type.

Method used

By retrieving timeout setting information from the Redis database, determining the timeout setting type, creating a first string, and using this string to set the timeout for fields in the hash type, the timeout management effect of the hash type is improved.

Benefits of technology

It enables effective timeout management for fields in hash types, improves the effectiveness of timeout settings for hash types, reduces operational errors, and minimizes the impact on database performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116910053B_ABST
    Figure CN116910053B_ABST
Patent Text Reader

Abstract

This invention provides a data timeout management method, apparatus, electronic device, and readable storage medium, relating to the field of computer technology. The method includes: acquiring timeout setting information from a Redis database, the timeout setting information including a key and an expiration time corresponding to a hash type, wherein the hash type is a triple of key, field, and value; determining the timeout setting type of the hash type based on the current key, the timeout setting type including a first type and a second type; if the timeout setting type is the first type, creating a first string based on the current key, wherein the value of the first string corresponds to the expiration time; and setting a timeout for the field in the hash type based on the first string. This invention improves the effectiveness of hash type timeout management by setting timeouts for the fields in the hash type.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a data timeout management method, apparatus, electronic device, and readable storage medium. Background Technology

[0002] Redis is a fully open-source, high-performance database that adheres to the Berkeley Software Distribution (BSD) license. Redis includes five data types: String, List, Set, Sorted Set, and Hash. Hash is a mapping table between String type fields and values, and the Hash type is particularly suitable for storing objects.

[0003] In existing technologies, Redis supports setting an expiration time for Hash type caches, that is, setting an expiration time for a specified key, but it cannot set an expiration time for each field in the key.

[0004] It is evident that existing technologies have a poor effect on timeout management for hash types. Summary of the Invention

[0005] This invention provides a data timeout management method, apparatus, electronic device, and readable storage medium to solve the problem of poor timeout management for hash types in the prior art.

[0006] To solve the above problems, the present invention is implemented as follows:

[0007] In a first aspect, embodiments of the present invention provide a data timeout management method, comprising:

[0008] Retrieve timeout settings information from the Redis database. The timeout settings information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field, and value.

[0009] The timeout setting type of the hash type is determined based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0010] When the timeout setting type is the first type, a first string is created based on the current key, wherein the value of the first string corresponds to the expiration time;

[0011] Set a timeout for the field in the hash type based on the first string.

[0012] Secondly, embodiments of the present invention also provide a data timeout management device, comprising:

[0013] The first acquisition module is used to acquire timeout setting information in the Redis database. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field and value.

[0014] The determining module is used to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0015] The first creation module is used to create a first string based on the current key when the timeout setting type is the first type, wherein the value of the first string corresponds to the expiration time;

[0016] The setting module is used to set the timeout for the fields in the hash type based on the first string.

[0017] Thirdly, embodiments of the present invention also provide an electronic device, including a transceiver and a processor.

[0018] The transceiver is used to obtain timeout setting information from the Redis database. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field, and value.

[0019] The processor is configured to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0020] The processor is further configured to, when the timeout setting type is the first type, create a first string based on the current key, wherein the value of the first string corresponds to the expiration time;

[0021] The processor is further configured to set a timeout for the field in the hash type based on the first string.

[0022] Fourthly, embodiments of the present invention also provide an electronic device, including a transceiver, a memory, a processor, and a program stored in the memory and executable on the processor; characterized in that the processor is configured to read the program in the memory to implement the steps in the data timeout management method as described in the first aspect.

[0023] Fifthly, embodiments of the present invention also provide a readable storage medium for storing a program, which, when executed by a processor, implements the steps of the data timeout management method described in the first aspect above.

[0024] In this embodiment of the invention, timeout setting information is first obtained from the Redis database. It should be understood that this timeout setting information corresponds to a hash type in the Redis database, and includes the key and expiration time corresponding to the hash type. Then, based on the current key of the hash type, the target of the timeout setting is determined. If it is determined that the timeout setting is applied to a field, a first string is created based on the current key. Finally, the expiration time in the timeout setting information is used to set the timeout for the first string, thus completing the setting of the field in the hash type. By introducing a first string to set the timeout for the field in the hash type, the timeout management effect of the hash type is improved. Attached Figure Description

[0025] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0026] Figure 1 This is a flowchart illustrating a data timeout management method provided in an embodiment of the present invention;

[0027] Figure 2 This is a schematic diagram of the structure of a data timeout management device provided in an embodiment of the present invention;

[0028] Figure 3 This is a structural diagram of a communication device provided in an embodiment of the present invention. Detailed Implementation

[0029] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0030] In the embodiments of this invention, the terms "first," "second," etc., are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices.

[0031] Please see Figure 1 , Figure 1 This is a flowchart of a data timeout management method provided in an embodiment of the present invention, such as... Figure 1 As shown, it includes the following steps:

[0032] Step 101: Obtain the timeout setting information in the Redis database. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field and value.

[0033] Step 102: Determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0034] Step 103: When the timeout setting type is the first type, create a first string based on the current key, wherein the value of the first string corresponds to the expiration time;

[0035] Step 104: Set a timeout for the field in the hash type based on the first string.

[0036] In this embodiment of the invention, steps 101, 102, 103 and 104 of the above method for determining trajectory points can be executed by electronic devices, such as computers, and this is not limited.

[0037] First, the Remote Dictionary Server (Redis) is a fully open-source, high-performance database that complies with the Berkeley Software Distribution (BSD) license. Steps 101, 102, 103, and 104 of the aforementioned data timeout management method can be executed based on Java probe technology. After Java classes are compiled, they form bytecode that is executed by the Java Virtual Machine (JVM). The Java probe can obtain this bytecode before the JVM executes it and modify it through a bytecode converter to complete the addition of functionality.

[0038] It should be noted that before calling the Java probe, the plugin needs to be developed according to the development specifications, and relevant parameters need to be added to the program to be executed. This allows the bytecode to be inserted according to the plugin's content after the program runs, thereby enhancing the functionality.

[0039] It should be understood that the plugin is loaded by running relevant parameters during program execution, therefore there is no code intrusion during the execution of steps 102 to 104 above.

[0040] In step 101, the timeout setting information may include the key corresponding to the hash type and the expiration time. It should be understood that the Redis database provides the expire series of commands to set timeouts for different data types, but timeout settings can only be applied to keys. Hash types can be represented as triples, such as [key, field, value]. Therefore, when setting a timeout for a hash type in the Redis database, the key in the timeout setting information can be understood as a new key concatenated from the key and field of the target hash type according to certain concatenation rules.

[0041] In addition, the expiration time can be set according to the user's needs. For example, if the user sets the expiration time to 24 hours, then the data stored in the database needs to be deleted 24 hours after the expiration is successfully set.

[0042] It should be noted that the operation of obtaining the above timeout setting information in step 101 can be understood as using a plugin to intercept the expire series of commands that set the timeout.

[0043] In step 102, the actual purpose of the user setting the timeout is determined, that is, whether the user sets a timeout for the key in the hash type or for the field in the hash type. In this case, the key in the timeout setting information can be parsed. As mentioned above, the key in the timeout setting information can be understood as a new key concatenated from the key and field in the target hash type according to certain concatenation rules. Therefore, we can parse the key in the timeout setting information to see if the corresponding hash type key and field can be parsed out. If so, it means that the user's purpose in setting the timeout is to set a timeout for the field.

[0044] It should be noted that if the timeout setting type is the second type, that is, the user sets a timeout for the current key, then the expire series of commands will continue to be called to set a timeout for the current key.

[0045] In step 103, the first string is created based on the current key, and the first string can be timed out according to the expire series of commands. The value in the first string can represent the expiration time.

[0046] In step 104, after setting a timeout for the first string using the `expire` series of commands, the timeout setting for the field in the hash type is completed. This can be understood as the timeout setting of the first string matching the timeout setting of the corresponding field in the hash type.

[0047] In this implementation, the timeout setting information in the Redis database is first obtained. This timeout setting information corresponds to a hash type in the Redis database, and includes the key and expiration time of the hash type. Then, based on the current key of the hash type, the target of the timeout setting is determined. If it is determined that the timeout setting is applied to a field, a first string is created based on the current key. Finally, the expiration time in the first string is used to set the timeout, thus completing the setting of the field in the hash type. By introducing a first string to set the timeout for fields in a hash type, the timeout management effect of hash types is improved.

[0048] Optionally, determining the timeout setting type of the hash type based on the current key includes:

[0049] Get the first character of the current key;

[0050] If the first character satisfies the first preset condition, the timeout setting type is set to the first type;

[0051] If the first character does not meet the first preset condition, the timeout setting type is set to the second type;

[0052] Wherein, the first preset condition indicates that the first character is of the first character type, and the first character is used as a separator to split the current key into two non-empty strings, and the first character type indicates characters that are not numbers, not letters, and not underscores.

[0053] In this implementation scheme, the first character of the current key is first obtained, and it is determined whether the first character is a non-numeric type, a non-letter type, or a non-underscore type. If the first preset condition is met, the timeout setting type is set to the first type, which means that the user's purpose is to set a timeout for the field in the hash type. Through this method, the type of timeout setting can be determined, the user's setting intention can be clarified, the operational errors in managing data timeout can be reduced, and the timeout setting effect of data can be improved.

[0054] The first preset condition indicates that the first character is of the first character type, and the current key is split into two non-empty strings using the first character as a separator. The first character type indicates characters that are not numbers, letters, or underscores. The two non-empty strings can be used as the key and field of the hash type in the above order.

[0055] In some alternative implementations, the following rules are set:

[0056] 1. The current key begins with a non-numeric, non-letter, and non-underscore character.

[0057] 2. Using the first character as the delimiter, the remaining part after removing the first character can be divided into two strings, neither of which can be empty. These two strings are then used as the key and field of the hash type mentioned above, respectively.

[0058] According to the above rules, if the received current key is "@user@pwd", the plugin will determine that it is a timeout setting for the field in the above hash type. Because the character '@' is used as a separator, the remaining string "user@pwd" will be split into two parts, user and pwd, by the character '@'. The plugin will determine that user is the key of the above hash type and pwd is the field of the above hash type.

[0059] Similarly, keys like "user@pwd", "@user@", and "@user*pwd" will be considered non-compliant with the above rules and will be treated as regular timeout settings for the key. "*user*pwd", on the other hand, will be treated as a timeout setting for a field in a hash type. These rules allow for the appropriate selection of delimiters to handle cases where the key contains special characters.

[0060] Optionally, creating the first string based on the current key includes:

[0061] Set the prefix of the current key to a preset string to obtain the new key;

[0062] The first string is created based on the new key, wherein the value in the first string represents the expiration time.

[0063] In this implementation, a preset string is added to the prefix position of the current key to obtain a new key. Then, a string type data is created based on the new key, namely the first string mentioned above. The key in the first string is the new key, and the value is the expiration time. Finally, the expiration time is set on the first string using the `expire` series of commands. This method transforms the timeout setting, which would normally apply to fields in the hash type, into a timeout setting for a string type, thereby improving the effectiveness of hash type timeout settings.

[0064] It should be noted that when the plugin detects that a timeout setting is being applied to a field in a hash type, it can first check if the corresponding hash field exists; if it does not exist, it returns the result.

[0065] The above preset prefix can be set by the user. For example, with the current key "@user@pwd", according to the concatenation rules of the new key, a string type named "_hfexpire@user@pwd" will be created. The value in the string type is the specific expiration time, and the expiration time of the corresponding key will be set using the expire series of commands.

[0066] Optionally, after determining the timeout setting type of the hash type based on the current key, the method further includes:

[0067] The current key is split using the first character as the delimiter to obtain the parsing result, which includes a second string and a third string, wherein the second string represents the hash type key and the third string represents the hash type field;

[0068] Create an ordered set (zset), wherein the key of the ordered set is the concatenation key of the preset string and the second string;

[0069] Add the third string to the ordered set.

[0070] In this implementation scheme, the current key is first parsed to obtain the second string and the third string mentioned above. Then, an ordered set (zset) is created, and the third string is added to the ordered set. Using this method, when setting timeouts for other hash types or deleting expired data, the corresponding operations can be performed based on the ordered set, thereby improving the timeout setting effect for hash types.

[0071] In some embodiments, taking the current key "@user@pwd" as an example, according to the first preset condition mentioned above, if it is determined that the field in the hash type is to be timed out, then the plugin will add "pwd" to the ordered set with "_hfexpire_user" as the key. Furthermore, the corresponding ordered set does not need to be created in advance. If the Redis database finds that the ordered set does not exist during the addition process, it will automatically add it.

[0072] Optionally, after setting a timeout for the field in the hash type based on the first string, the method further includes:

[0073] Receive a deletion notification if the field of the hash type becomes invalid;

[0074] Based on the deletion notification, a first deletion process and a second deletion process are performed, wherein the first deletion process indicates the deletion of the field in the hash type, and the second deletion process indicates the deletion of the third string in the sorted set.

[0075] In this implementation scheme, because Redis provides timeout notifications, when the field of the aforementioned hash type expires, the deletion notification can be retrieved, and then the field in the aforementioned hash type and the aforementioned third string in the aforementioned ordered set can be deleted according to the deletion notification. This method utilizes Redis's own key expiration mechanism for deletion processing, eliminating the need to start a separate detection thread for periodic traversal detection. In the above scheme, the aforementioned first deletion processing and the aforementioned second deletion processing are required. Since Redis provides a pipeline mechanism, the impact on Redis performance is reduced, thereby improving the effectiveness of hash type timeout management.

[0076] Taking the received notification of the key "_hfexpire@user@pwd" being expired as an example, according to the concatenation rules, it can be parsed that the hash type has expired. The key of the hash type is "user" and the field of the hash type is "pwd". Then, "pwd" is deleted from the ordered set corresponding to "_hfexpire_user" and the corresponding field in the hash type is also deleted.

[0077] Optionally, after setting a timeout for the field in the hash type based on the first string, the method further includes:

[0078] Intercept the target method containing the hash type and obtain N target keys and N target fields corresponding to the hash type, where N is a positive integer;

[0079] The target key and the target field are concatenated one-to-one to obtain N new target keys.

[0080] Based on the N target new keys and the ordered set, invalid fields in the hash type are deleted.

[0081] In this implementation scheme, the target methods containing the above-mentioned hash type are first intercepted, and N target keys and N target fields corresponding to the above hash type are obtained. Then, the N target keys and N target fields are concatenated one-to-one according to the concatenation rules to obtain N new target keys. Finally, the N new target keys are compared with the above-mentioned ordered set, and the invalid fields in the above hash type are deleted. Through this method, the expiration of fields with timeout settings can be detected in real time, thereby achieving an efficient cleanup effect.

[0082] In some alternative embodiments, the plugin intercepts methods containing hash types and parses the parameters. It uses the key and all fields to concatenate them according to concatenation rules. Then, it uses the mget command in the Redis database to retrieve all keys that have not expired at once and compares them with the keys in the sorted set. Fields that exist in the sorted set but are not returned by the mget command are set as expired fields. Finally, the Redis database calls the hdel command to delete the expired fields.

[0083] It should be noted that Redis uses lazy deletion to clean up expired keys. Therefore, in the above embodiment, after calling the mget command, the returned key is the key that has not expired. At this time, the logic of deleting expired keys will be triggered for keys that have expired but have not been deleted. During this period, it is necessary to use an ordered set to determine the key with the expiration time. By comparison, it can be confirmed that the key has expired but has not been deleted.

[0084] Optionally, the step of deleting invalid fields in the hash type based on the N target new keys and the ordered set includes:

[0085] Obtain the M keys that have not expired from the N target new keys, where M is an integer greater than or equal to 0 and less than or equal to N;

[0086] Based on the M keys that have not expired, delete the invalid fields in the ordered set.

[0087] Please see Figure 2 , Figure 2 This is a schematic diagram of the structure of a data timeout management device provided in an embodiment of the present invention, as shown below. Figure 2 As shown, the data timeout management device 200 includes:

[0088] The first acquisition module 201 is used to acquire timeout setting information in the database Redis. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field and value.

[0089] The determining module 202 is used to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0090] The first creation module 203 is used to create a first string based on the current key when the timeout setting type is the first type, wherein the value of the first string corresponds to the expiration time;

[0091] Setting module 204 is used to set timeout for the fields in the hash type based on the first string.

[0092] Optionally, the determining module 202 includes:

[0093] The first retrieval unit is used to retrieve the first character of the current key;

[0094] The first setting unit is used to set the timeout setting type to the first type when the first character meets the first preset condition;

[0095] The second setting unit is used to set the timeout setting type to the second type when the first character does not meet the first preset condition;

[0096] Wherein, the first preset condition indicates that the first character is of the first character type, and the first character is used as a separator to split the current key into two non-empty strings, and the first character type indicates characters that are not numbers, not letters, and not underscores.

[0097] Optionally, the first creation module 203 includes:

[0098] The third setting unit is used to set the prefix of the current key to a preset string to obtain the new key.

[0099] The first creation unit is used to create the first string based on the new key, wherein the value in the first string represents the expiration time.

[0100] Optionally, the data timeout setting device 200 further includes:

[0101] The splitting module is used to split the current key using the first character as the delimiter to obtain the parsing result. The parsing result includes a second string and a third string, wherein the second string represents the hash type key and the third string represents the hash type field.

[0102] The second creation module is used to create an ordered set (zset), wherein the key of the ordered set is the concatenation key of the preset string and the second string;

[0103] An add module is used to add the third string to the ordered set.

[0104] Optionally, the data timeout setting device 200 further includes:

[0105] The second acquisition module is used to acquire a deletion notification when the field of the hash type becomes invalid;

[0106] The first deletion module is used to perform a first deletion process and a second deletion process based on the deletion notification, wherein the first deletion process indicates the deletion of the field in the hash type, and the second deletion process indicates the deletion of the third string in the sorted set.

[0107] Optionally, the data timeout setting device 200 further includes:

[0108] The third acquisition module is used to intercept the target method containing the hash type and acquire N target keys and N target fields corresponding to the hash type, where N is a positive integer;

[0109] The concatenation module is used to concatenate the target key and the target field one-to-one to obtain N new target keys.

[0110] The second deletion module is used to delete invalid fields in the hash type based on the N target new keys and the ordered set.

[0111] Optionally, the second deletion module includes:

[0112] The second acquisition unit is used to acquire M keys that have not expired from the N target new keys, where M is an integer greater than or equal to 0 and less than or equal to N;

[0113] The deletion unit is used to delete expired fields in the ordered set based on the M keys that have not expired.

[0114] Specifically, please see Figure 3 The present invention also provides an electronic device, including a bus 301, a transceiver 302, an antenna 303, a bus interface 304, a processor 305, and a memory 306.

[0115] Transceiver 302 is used to obtain timeout setting information from the database Redis. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field and value.

[0116] Processor 305 is configured to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key.

[0117] The processor 305 is further configured to, when the timeout setting type is the first type, create a first string based on the current key, wherein the value of the first string corresponds to the expiration time;

[0118] The processor 305 is also configured to set a timeout for the field in the hash type based on the first string.

[0119] Optionally, transceiver 302 is also used to obtain the first character of the current key;

[0120] The processor 305 is further configured to set the timeout setting type to the first type when the first character satisfies the first preset condition;

[0121] The processor 305 is further configured to set the timeout setting type to the second type if the first character does not meet the first preset condition;

[0122] Wherein, the first preset condition indicates that the first character is of the first character type, and the first character is used as a separator to split the current key into two non-empty strings, and the first character type indicates characters that are not numbers, not letters, and not underscores.

[0123] Optionally, the processor 305 is also configured to set the prefix of the current key to a preset string to obtain a new key;

[0124] The processor 305 is further configured to create the first string based on the new key, wherein the value in the first string represents the expiration time.

[0125] Optionally, the processor 305 is further configured to split the current key using the first character as a delimiter to obtain a parsing result, wherein the parsing result includes a second string and a third string, wherein the second string represents the hash type key and the third string represents the hash type field;

[0126] The processor 305 is also configured to create an ordered set zset, wherein the key of the ordered set is the concatenation key of the preset string and the second string;

[0127] Processor 305 is also configured to add the third string to the ordered set.

[0128] Optionally, transceiver 302 is also configured to receive a deletion notification in the event that the hash-type field becomes invalid;

[0129] The processor 305 is further configured to perform a first deletion process and a second deletion process based on the deletion notification, wherein the first deletion process indicates the deletion of a field in the hash type, and the second deletion process indicates the deletion of the third string in the sorted set.

[0130] Optionally, transceiver 302 is further configured to intercept a target method containing the hash type and obtain N target keys and N target fields corresponding to the hash type, where N is a positive integer;

[0131] The processor 305 is also used to perform a one-to-one concatenation of the target key and the target field to obtain N new target keys;

[0132] The processor 305 is also configured to delete invalid fields in the hash type based on the N target new keys and the ordered set.

[0133] Optionally, the transceiver 302 is further configured to acquire M keys that have not expired from the N target new keys, where M is an integer greater than or equal to 0 and less than or equal to N;

[0134] The processor 305 is also configured to delete expired fields in the ordered set based on the M non-expired keys.

[0135] exist Figure 3 In this document, a bus architecture (represented by bus 301) is used. Bus 301 can include any number of interconnected buses and bridges, linking various circuits including one or more processors represented by processor 305 and memory represented by memory 306. Bus 301 can also link various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be described further herein. Bus interface 304 provides an interface between bus 301 and transceiver 302. Transceiver 302 can be a single element or multiple elements, such as multiple receivers and transmitters, providing a unit for communicating with various other devices over a transmission medium. Data processed by processor 305 is transmitted over a wireless medium via antenna 303, which further receives data and transmits it to processor 305.

[0136] Processor 305 manages bus 301 and general processing, and also provides various functions, including timing, peripheral interface, voltage regulation, power management, and other control functions. Memory 306 can be used to store data used by processor 305 during operation.

[0137] Optionally, the processor 305 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or a complex programmable logic device (CPLD).

[0138] This invention also provides an electronic device, including: a processor, a memory, and a program stored in the memory and executable on the processor. When the program is executed by the processor, it implements the various processes of the above-described data timeout management method embodiments and achieves the same technical effect. To avoid repetition, it will not be described again here.

[0139] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of the present invention is not limited to performing functions in the order discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0140] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0141] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.

Claims

1. A data timeout management method, characterized in that, include: Retrieve timeout settings information from the Redis database. The timeout settings information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field, and value. The timeout setting type of the hash type is determined based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key. When the timeout setting type is the first type, a first string is created based on the current key, wherein the value of the first string corresponds to the expiration time; Set a timeout for the field in the hash type based on the first string; The step of determining the timeout setting type of the hash type based on the current key includes: Get the first character of the current key; If the first character satisfies the first preset condition, the timeout setting type is set to the first type; If the first character does not meet the first preset condition, the timeout setting type is set to the second type; Wherein, the first preset condition indicates that the first character is of the first character type, and the current key is split into two non-empty strings using the first character as a separator; the first character type indicates characters that are not numbers, not letters, and not underscores. After determining the timeout setting type of the hash type based on the current key, the method further includes: The current key is split using the first character as a delimiter to obtain the parsing result, which includes a second string and a third string, wherein the second string represents the key of the hash type and the third string represents the field of the hash type.

2. The data timeout management method according to claim 1, characterized in that, The process of creating the first string based on the current key includes: Set the prefix of the current key to a preset string to obtain the new key; The first string is created based on the new key, wherein the value in the first string represents the expiration time.

3. The data timeout management method according to claim 2, characterized in that, After determining the timeout setting type of the hash type based on the current key, the method further includes: Create an ordered set (zset), wherein the key of the ordered set is the concatenation key of the preset string and the second string; Add the third string to the ordered set.

4. The data timeout management method according to claim 3, characterized in that, After setting a timeout for the field in the hash type based on the first string, the method further includes: Receive a deletion notification if the field of the hash type becomes invalid; Based on the deletion notification, a first deletion process and a second deletion process are performed, wherein the first deletion process indicates the deletion of the field in the hash type, and the second deletion process indicates the deletion of the third string in the sorted set.

5. The data timeout management method according to claim 3, characterized in that, After setting a timeout for the field in the hash type based on the first string, the method further includes: Intercept the target method containing the hash type and obtain N target keys and N target fields corresponding to the hash type, where N is a positive integer; The target key and the target field are concatenated one-to-one to obtain N new target keys. Based on the N target new keys and the ordered set, invalid fields in the hash type are deleted.

6. The data timeout management method according to claim 5, characterized in that, The step of deleting invalid fields from the hash type based on the N target new keys and the ordered set includes: Obtain the M keys that have not expired from the N target new keys, where M is an integer greater than or equal to 0 and less than or equal to N; Based on the M keys that have not expired, delete the invalid fields in the ordered set.

7. A data timeout management device, characterized in that, include: The first acquisition module is used to acquire timeout setting information in the Redis database. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field and value. The determining module is used to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key. The first creation module is used to create a first string based on the current key when the timeout setting type is the first type, wherein the value of the first string corresponds to the expiration time; The setting module is used to set the timeout for the fields in the hash type based on the first string; The determining module includes: The first retrieval unit is used to retrieve the first character of the current key; The first setting unit is used to set the timeout setting type to the first type when the first character meets the first preset condition; The second setting unit is used to set the timeout setting type to the second type when the first character does not meet the first preset condition; Wherein, the first preset condition indicates that the first character is of the first character type, and the first character is used as a separator to split the current key into two non-empty strings, and the first character type indicates characters that are not numbers, not letters, and not underscores; The splitting module is used to split the current key using the first character as the delimiter to obtain the parsing result. The parsing result includes a second string and a third string, wherein the second string represents the hash type key and the third string represents the hash type field.

8. An electronic device, characterized in that, Including transceivers and processors, The transceiver is used to obtain timeout setting information from the Redis database. The timeout setting information includes the key and expiration time corresponding to the hash type Hash. The hash type is a triple of key, field, and value. The processor is configured to determine the timeout setting type of the hash type based on the current key of the hash type. The timeout setting type includes a first type and a second type, wherein the first type represents the timeout setting for the field, and the second type represents the timeout setting for the current key. The processor is further configured to, when the timeout setting type is the first type, create a first string based on the current key, wherein the value of the first string corresponds to the expiration time; The processor is further configured to set a timeout for the field in the hash type based on the first string; The transceiver is also used to obtain the first character of the current key; The processor is further configured to set the timeout setting type to the first type when the first character satisfies the first preset condition; The processor is further configured to set the timeout setting type to the second type if the first character does not meet the first preset condition; Wherein, the first preset condition indicates that the first character is of the first character type, and the current key is split into two non-empty strings using the first character as a separator; the first character type indicates characters that are not numbers, not letters, and not underscores. The processor is further configured to split the current key using the first character as a delimiter to obtain a parsing result, wherein the parsing result includes a second string and a third string, wherein the second string represents the hash type key and the third string represents the hash type field.

9. An electronic device, characterized in that, include: A transceiver, a memory, a processor, and a program stored in the memory and executable on the processor; characterized in that the processor is configured to read the program in the memory to implement the steps of the data timeout management method as described in any one of claims 1 to 6.

10. A readable storage medium for storing a program, characterized in that, When the program is executed by the processor, it implements the steps of the data timeout management method as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • A data processing method and a device based on a Redis Hash structure

    CN109101635A

  • Domain life cycle control method, system, server and storage medium for realizing HASH key of Redis

    CN109344296A

  • Timeout processing optimization method and storage medium

    CN111600738A