Data storage method, device, computing equipment and storage medium
By filtering and adjusting data in the in-memory storage database and dynamically managing storage duration, the problem of excessive storage space usage and low resource utilization is solved, achieving more efficient storage management and improving user experience.
Patent Information
- Application Number
- CN202111144127.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-28
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-09-28
AI Technical Summary
When using an in-memory storage database, the storage space is too large, resource utilization is low, and data cleaning is complicated, which may cause system failures and affect user experience.
By filtering out the storage data to be managed from the database, setting multiple adjustment times, the remaining storage time of the stored data is dynamically adjusted according to user access behavior. If the storage time is less than or equal to zero, the data is deleted to avoid permanent occupation of storage space.
It improves storage resource utilization, reduces the number of database queries, improves user experience, and ensures stable system operation.
Smart Images

Figure CN113849131B
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and in particular to a data storage method, device, computing equipment and storage medium. Background Art
[0002] Databases that store data in memory (such as Redis database) have greatly improved read and write performance. In terms of improving user experience and increasing system throughput (Transactions Per Second, TPS), memory-storage databases have obvious advantages.
[0003] When the business system uses a memory-storage database, the space is already allocated when the memory-storage database cluster is initially built. As the business grows, the remaining storage space of the memory-storage database will become less and less. Before the storage reaches a bottleneck, manual capacity expansion is required to ensure the stable operation of the business. Among the business data that occupies the storage space of the memory-storage database, a lot of data can be cleaned up and deleted, and the cleaning of this part of data will not affect the stable operation of the business system. However, a business system is often divided into many sub-application systems, and each sub-application incorporates many different businesses. The data cleaning work is often extremely complicated, and the slightest carelessness will lead to serious system failures.
[0004] Take the Redis database as an example. Figure 1 It is a schematic diagram of Redis database application in the prior art, such as Figure 1 As shown in the figure, the data stored in the Redis database by the business system is divided into permanent data and temporary data. Permanent data permanently occupies space, and temporary data needs to be stored for a fixed time. The business system can only access the data in Redis within this fixed time. After this fixed time, it needs to be retrieved from the relational database (such as MySQL database). For these two types of data, permanent data will cause a large amount of garbage data to be generated, and the fixed time of temporary data will cause frequent penetration of the relational database to obtain data, affecting the user experience.
[0005] Two application cases of the prior art solution include: Case 1, a video file is stored in a Redis database, occupying 100M of space as permanent data storage. After that, regardless of whether there is a user accessing the video file, the video file will permanently occupy 100M of storage space. A large amount of similar data will occupy all the storage space of Redis;
[0006] Case 2: A video file is stored in a Redis database, which takes up 100M of space as temporary data storage. The storage duration is set to 7 days. If a user accesses the file within 7 days, the data will be obtained from the Redis database. If the user accesses the file again after 7 days, the data needs to be pulled from the relational database and loaded into the Redis database. Within 7 days after the data is loaded again, the user can obtain the data from the Redis database. After another 7 days, the data needs to be pulled from the relational database and loaded again, and the cycle continues.
[0007] However, the permanent data loaded into Redis in the above cases 1 and 2 permanently occupies Redis space, has low resource utilization, and takes a long time to operate; temporary data with a fixed time, if used once by the user and no longer used, will definitely occupy Redis space within a preset fixed time, and will only be cleared and released by Redis after the preset fixed time. If the user uses the data again after the data is cleared, the data needs to be obtained from the relational database again, resulting in a poor user experience. Summary of the invention
[0008] In view of the above problems, the present invention is proposed to provide a data storage method, apparatus, computing device and storage medium that overcome the above problems or at least partially solve the above problems.
[0009] According to one aspect of the present invention, there is provided a data storage method, comprising:
[0010] Filter the storage data to be managed from the database and set multiple adjustment times;
[0011] At the tth adjustment time, adjusting the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed, where t is greater than 1;
[0012] If the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero, the storage data to be managed is deleted from the database.
[0013] According to another aspect of the present invention, there is provided a data storage device, comprising:
[0014] The initial module is used to filter the storage data to be managed from the database and set multiple adjustment moments;
[0015] an adjustment module, configured to adjust the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed at the tth adjustment time, wherein t is greater than 1;
[0016] The data processing module is used to delete the storage data to be managed from the database if the remaining storage time of the storage data to be managed after adjustment is less than or equal to zero.
[0017] According to another aspect of the present invention, there is provided a computing device, comprising: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0018] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute an operation corresponding to the above-mentioned data storage method.
[0019] According to another aspect of the present invention, a computer storage medium is provided, wherein the storage medium stores at least one executable instruction, and the executable instruction enables a processor to execute an operation corresponding to the above-mentioned data storage method.
[0020] According to a data storage method, device, computing device and storage medium of the present invention, the method selects the storage data to be managed from the database and sets multiple adjustment moments; at the tth adjustment moment, according to the user's access behavior to the storage data to be managed, the remaining storage time of the storage data to be managed is adjusted, wherein t is greater than 1; if the remaining storage time of the storage data to be managed after adjustment is less than or equal to zero, the storage data to be managed is deleted from the database. The present invention does not store permanent data but stores temporary data, eliminating the possibility of storage space being permanently occupied; by setting multiple adjustment moments, the remaining storage time of the storage data to be managed is adjusted according to whether the storage data to be managed is accessed by a user, so that the temporary data is not stored at a fixed time, and the remaining storage time of the storage data to be managed is dynamically extended if there is a user access, which can effectively reduce the number of queries to the database, and if there is no user access, the remaining storage time of the storage data to be managed is dynamically shortened or the storage data to be managed is deleted, which can achieve the purpose of quickly releasing space, improve storage resource utilization, and enhance user experience.
[0021] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented according to the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the present invention. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0023] Figure 1 A schematic diagram of a Redis database application in the prior art of the present invention is shown;
[0024] Figure 2 A flow chart of a data storage method provided by an embodiment of the present invention is shown;
[0025] Figure 3 A schematic diagram of a Redis database application of a data storage method provided by an embodiment of the present invention is shown;
[0026] Figure 4 A data time curve diagram of a data storage method provided by an embodiment of the present invention is shown;
[0027] Figure 5 A schematic diagram of the structure of a data storage device provided by an embodiment of the present invention is shown;
[0028] Figure 6 A schematic diagram of the structure of a computing device provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0029] The exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided in order to enable a more thorough understanding of the present invention and to enable the scope of the present invention to be fully communicated to those skilled in the art.
[0030] Figure 2 A flow chart of an embodiment of a data storage method of the present invention is shown as follows: Figure 2 As shown, the method comprises the following steps:
[0031] Step S210: Filter the storage data to be managed from the database and set multiple adjustment times.
[0032] In an optional manner, the database specifically includes a memory storage database, etc.
[0033] Traditional databases are relational databases that store data on disk, while the database of this embodiment may be a database that uses memory to store data. Taking the Redis database as an example, the Redis database uses memory to store data, and its read and write performance is greatly improved compared to the disk storage data of the relational database. The Redis database has obvious advantages in improving user experience and increasing system throughput (Transactions Per Second, TPS).
[0034] In order to calculate the remaining storage time of the storage data that occupies too much space in the memory storage database so as to re-manage it and thus free up space in the memory storage database, step S210 further includes: filtering out storage data whose data size is greater than a preset threshold from the memory storage database as storage data to be managed; wherein the preset threshold can be the size of the space occupied by the storage data, such as 100M.
[0035] This embodiment uses the Redis database as an example to illustrate a data storage method. Figure 3 Schematic diagram of Redis database application of the data storage method of this embodiment. Figure 3 As shown, compared with the prior art, this embodiment effectively manages the storage data to be managed by adding a Redis data storage manager; first, the storage space threshold that requires data management is configured in the Redis data storage manager, and a preset threshold is set according to the storage space threshold, and the storage data with a data size greater than the preset threshold is screened out from the Redis database as the storage data to be managed, and handed over to the Redis data storage manager for management, and the storage data to be managed is not used as permanent data storage, but only as temporary data storage, so that the storage data to be managed is not stored for a fixed time, thereby avoiding permanent occupation of storage space.
[0036] Furthermore, after filtering out the storage data to be managed, the Redis data storage manager needs to be initialized and configured, thereby starting the Redis data storage manager; specifically, by setting multiple adjustment moments, each two adjacent adjustment moments are an adjustment interval a, for example, the 0th adjustment moment - the 1st adjustment moment is adjustment interval 1, the 1st adjustment moment - the 2nd adjustment moment is adjustment interval 2, and so on. In an optional manner, multiple adjustment moments are set every second preset time period from the initial storage moment of the storage data to be managed; technical personnel in this field can set the second preset time period according to actual needs. If the second preset time period is set to 1 minute, an adjustment moment is set every one minute; in addition, it is also necessary to preset the storage time peak e of the storage data to be managed and the first preset time period f.
[0037] Step S220: at the tth adjustment time, adjusting the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed, where t is greater than 1.
[0038] In an optional manner, step S220 further includes: determining the starting adjustment parameter corresponding to the tth adjustment moment based on the user's access behavior to the storage data to be managed; calculating the remaining storage time of the storage data to be managed after adjustment corresponding to the tth adjustment moment based on the starting adjustment parameter, the preset storage time peak, the first preset time, and the time between the tth adjustment moment and the 0th adjustment moment; wherein the 0th adjustment moment is the initial storage moment of the storage data to be managed.
[0039] Specifically, the formula for calculating the remaining storage time is as follows (1):
[0040]
[0041] Among them, (x′, y′) is the starting adjustment parameter corresponding to the tth adjustment moment, e is the preset storage duration peak, f is the first preset duration, x represents the duration between the tth adjustment moment and the 0th adjustment moment, and y is the remaining storage duration after this adjustment.
[0042] It should be noted that x represents the duration between the tth adjustment moment and the 0th adjustment moment. If the duration a between every two adjacent adjustment moments is set to 1 minute, it means that the remaining storage duration y is calculated every 1 minute. The smaller the value of the adjustment interval a is, the finer the adjustment of the remaining storage duration is. The storage duration peak e represents the maximum value of the remaining storage duration y derived from formula (1). If the maximum value of y derived from formula (1) is 30 minutes, the storage duration peak e is set to 30 minutes. The first preset duration f is calculated based on the pre-calculated storage data to be managed from the initial storage moment to the storage time. The duration of the long peak value e can be determined, which can be understood as the time difference from the moment when the storage data to be managed is stored (i.e., the 0th adjustment moment) to the storage duration peak e. For example, according to formula (1), the first preset duration f is derived to be 10 minutes, that is, the first preset duration f is set to 10 minutes, and the duration between the 0th adjustment moment and the 1st adjustment moment is set to 1 minute (i.e., the adjustment interval duration is 1 minute). If the storage data to be managed is stored at 11 o'clock, the remaining storage duration is calculated once every minute, and the storage duration peak e is obtained at 11:10 (i.e., the tenth calculation).
[0043] In an optional manner, step S220 further includes: determining the starting adjustment parameter corresponding to the tth adjustment moment based on whether the user has any access behavior for the storage data to be managed between the tth adjustment moment and the t-1th adjustment moment and between the t-1th adjustment moment and the t-2th adjustment moment.
[0044] In an optional manner, step S220 further includes: if there is an access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is an access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, or, there is no access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is no access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, then the starting adjustment parameter corresponding to the t-1-th adjustment moment is used as the starting adjustment parameter corresponding to the t-th adjustment moment; if there is no access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is an access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, then according to the t-1-th adjustment moment The starting adjustment parameter corresponding to the t-th adjustment moment is determined based on the duration between the adjustment moment and the 0th adjustment moment, the remaining storage duration of the storage data to be managed after adjustment corresponding to the t-1th adjustment moment, the preset storage duration peak value and the first preset duration; if there is an access behavior between the t-th adjustment moment and the t-1th adjustment moment and there is no access behavior between the t-1th adjustment moment and the t-2th adjustment moment, the starting adjustment parameter corresponding to the t-th adjustment moment is determined based on the duration between the t-1th adjustment moment and the 0th adjustment moment and the remaining storage duration of the storage data to be managed after adjustment corresponding to the t-1th adjustment moment; wherein, the starting adjustment parameter corresponding to the 1st adjustment moment is a preset parameter.
[0045] Specifically, the 0th adjustment moment is the initial storage moment of the storage data to be managed, and the starting adjustment parameter (x′, y′) corresponding to the 1st adjustment moment is a preset parameter, which is generally set to (0, 0). If there is an access behavior between the tth adjustment moment and the t-1th adjustment moment and there is an access behavior between the t-1th adjustment moment and the t-2th adjustment moment, the remaining storage time continues to increase, and the (x′, y′) corresponding to the tth adjustment moment is always calculated according to the preset parameter (0, 0); if there is no access behavior between the tth adjustment moment and the t-1th adjustment moment and there is no access behavior between the t-1th adjustment moment and the t-2th adjustment moment, the remaining storage time continues to decay, and the starting adjustment parameter corresponding to the t-1th adjustment moment is used as the starting adjustment parameter corresponding to the tth adjustment moment;
[0046] If there is no access behavior between the t-1 adjustment time and the t-2 adjustment time, and there is an access behavior between the t-1 adjustment time and the t-2 adjustment time, the remaining storage time calculated at the t-1 adjustment time will decay. In this case, the (x′, y′) corresponding to the t-1 adjustment time needs to be reset when performing the t-1 calculation. The calculation method is to determine the parameters (m, n) based on the time between the t-1 adjustment time and the 0th adjustment time and the remaining storage time of the storage data to be managed corresponding to the t-1 adjustment time after adjustment, where m is the time between the t-1 adjustment time and the 0th adjustment time, and n is the remaining storage time of the storage data to be managed corresponding to the t-1 adjustment time after adjustment; subtract f and e from (m, n) respectively, and deduce the new (x′, y′) corresponding to the t-1 adjustment time as (m–f, ne) and substitute it into formula (1) for calculation; in particular, if at the t-1 adjustment time If there is an access behavior between the adjustment moment and the t-1th adjustment moment and there is no access behavior between the t-1th adjustment moment and the t-2th adjustment moment, then the starting adjustment parameter corresponding to the tth adjustment moment is determined according to the duration between the t-1th adjustment moment and the 0th adjustment moment and the remaining storage duration after adjustment of the storage data to be managed corresponding to the t-1th adjustment moment. For example, if there is an access behavior between the 8th adjustment moment and the 7th adjustment moment and there is no access behavior between the 7th adjustment moment and the 6th adjustment moment, then in the 8th calculation (i.e., calculation at the 8th adjustment moment), it is necessary to increase the calculation according to the remaining storage duration, then (x′, y′) is reset again, wherein x′ is reset to the duration between the 7th adjustment moment and the 0th adjustment moment, and y′ is reset to the remaining storage duration after adjustment of the storage data to be managed corresponding to the 7th adjustment moment. At this time, there is no need to perform subtraction operations with f and e.
[0047] In order to avoid the remaining storage time of the storage data to be managed after adjustment exceeding the preset storage time peak value, resulting in excessive remaining storage time, and data redundancy caused by not cleaning up the data for too long, in an optional manner, step S220 further includes: judging whether the remaining storage time of the storage data to be managed after adjustment exceeds the third preset time; if so, taking the third preset time as the remaining storage time of the storage data to be managed after adjustment. Among them, the third preset time b can be set according to the value of the preset storage time peak e, and the configuration value of b should be less than or equal to e. For example, if e is set to 30 minutes, the configuration value of b should be a value less than or equal to 30 and greater than 0. For example, if b is configured as 20, when the calculated value of the remaining storage time y is greater than the third preset time (i.e., 20 minutes), the storage time is set to 20; when the remaining storage time y is less than 20, the remaining storage time is set according to the y value.
[0048] For example, taking e=30 minutes, f=10 minutes, the duration between the first adjustment time and the 0th adjustment time a=1 minute, and b=20 minutes as an example, an application scenario of this embodiment is listed, and the above parameters e and f are substituted into formula (1) to obtain formula (2) as follows:
[0049]
[0050] The adjustment process is as follows:
[0051] 1. The 0th adjustment time is the initial storage time of the storage data to be managed. The first adjustment time is the first calculation, which calculates the initial remaining storage time of the storage data to be managed.
[0052] When data is stored, it is calculated based on growth. The initial adjustment parameter (x′, y′) corresponding to the first adjustment time is the preset parameter (0, 0); at this time, x′=0, y′=0, the x value is 1×a (representing the duration between the first adjustment time and the 0th adjustment time), a is 1 minute, and x=1 is calculated; substituting it into formula (2) to calculate y=5.7, and at this time, the initial remaining storage duration of the stored data to be managed is set to 5.7 minutes.
[0053] 2. The second adjustment time is the second calculation
[0054] If there is access behavior between the 0th adjustment moment and the 1st adjustment moment, and there is access behavior between the 1st adjustment moment and the 2nd adjustment moment, the starting adjustment parameter corresponding to the 1st adjustment moment is used as the starting adjustment parameter corresponding to the 2nd adjustment moment, (x′, y′) is still (0, 0), at this time x′=0, y′=0, x=2×a (representing the duration between the 2nd adjustment moment and the 0th adjustment moment, the following calculation is similar and will not be repeated), a is 1 minute, and x=2 is obtained by substitution, and y=10.8 is obtained by substitution into formula (2), and the remaining storage duration of the stored data to be managed is set to 10.8 minutes.
[0055] 3. The third adjustment time is the third calculation
[0056] If there is access behavior between the first adjustment moment and the second adjustment moment and there is access behavior between the second adjustment moment and the third adjustment moment, the starting adjustment parameter corresponding to the second adjustment moment is used as the starting adjustment parameter corresponding to the third adjustment moment; that is, x′=0, y′=0, x=3×a=3, and y=15.3 is obtained by substituting into formula (2), then the remaining storage time of the stored data to be managed is set to 15.3 minutes.
[0057] 4. The fourth adjustment time is the fourth calculation
[0058] If there is access behavior between the second adjustment moment and the third adjustment moment and there is access behavior between the third adjustment moment and the fourth adjustment moment, the starting adjustment parameter corresponding to the third adjustment moment is used as the starting adjustment parameter corresponding to the fourth adjustment moment; that is, x′=0, y′=0, x=4×a=4, and y=19.2 is obtained by substituting into formula (2), then the remaining storage time of the stored data to be managed is set to 19.2 minutes.
[0059] 5. The fifth adjustment time is the fifth calculation
[0060] If there is access behavior between the 3rd adjustment moment and the 4th adjustment moment and there is access behavior between the 4th adjustment moment and the 5th adjustment moment, the starting adjustment parameter corresponding to the 4th adjustment moment is used as the starting adjustment parameter corresponding to the 5th adjustment moment; that is, x′=0, y′=0, x=5×a=5, and y=22.5 is obtained by substituting into formula (2), which is greater than the configured third preset time length b (20 minutes), and the remaining storage time of the stored data to be managed is set to 20 minutes according to the third preset time length b.
[0061] 6. The sixth adjustment time is the sixth calculation
[0062] If there is an access behavior between the 4th adjustment moment and the 5th adjustment moment and there is an access behavior between the 5th adjustment moment and the 6th adjustment moment, the starting adjustment parameter corresponding to the 5th adjustment moment will be used as the starting adjustment parameter corresponding to the 6th adjustment moment; that is, x′=0, y′=0, x=6×a=6. Since the remaining storage time at the 5th adjustment moment is greater than the configured third preset time b, no calculation is required this time, and the remaining storage time is directly set to 20 minutes according to the third preset time b.
[0063] 7. The 7th adjustment time is the 7th calculation
[0064] If there is an access behavior between the 5th adjustment moment and the 6th adjustment moment and there is an access behavior between the 6th adjustment moment and the 7th adjustment moment, the starting adjustment parameter corresponding to the 6th adjustment moment will be used as the starting adjustment parameter corresponding to the 7th adjustment moment; that is, x′=0, y′=0, x=7×a=7. Since the remaining storage time at the 6th adjustment moment is greater than the configured third preset time b, no calculation is required this time, and the remaining storage time is directly set to 20 minutes according to the third preset time b.
[0065] 8. The 8th adjustment time is the eighth calculation
[0066] If there is no access behavior between the 8th adjustment time and the 7th adjustment time and there is an access behavior between the 7th adjustment time and the 6th adjustment time, it means that attenuation needs to occur. At this time, it is necessary to reset (x′, y′). By using the time length between the 7th adjustment time and the 0th adjustment time m=7×a=7, n=the remaining storage time after adjustment of the storage data to be managed corresponding to the 7th adjustment time=20, and the preset values of f and e, it is calculated that x′=7–10=-3, y′=20–30=-10, x=8×a=8, and substituting it into formula (2) to calculate y=19.7, the remaining storage time is set to 19.7 minutes.
[0067] 9. The 9th adjustment time is the ninth calculation
[0068] If there is no access behavior between the 9th adjustment time and the 8th adjustment time and there is no access behavior between the 8th adjustment time and the 7th adjustment time, the starting adjustment parameter corresponding to the 8th adjustment time is used as the starting adjustment parameter corresponding to the 9th adjustment time; x′=-3, y′=-10, x=9×a=9, substitute into formula (2) to calculate y=18.8, then set the remaining storage time to 18.8 minutes.
[0069] 10. The 10th adjustment time is the tenth calculation
[0070] If there is no access behavior between the 10th adjustment time and the 9th adjustment time and there is no access behavior between the 9th adjustment time and the 8th adjustment time, the starting adjustment parameter corresponding to the 9th adjustment time is used as the starting adjustment parameter corresponding to the 10th adjustment time; x′=-3, y′=-10, x=10×a=10, substitute into formula (2) to obtain y=17.3, then set the remaining storage time to 17.3 minutes.
[0071] 11. The 11th adjustment time is the 11th calculation
[0072] If there is no access behavior between the 11th adjustment time and the 10th adjustment time and there is no access behavior between the 10th adjustment time and the 9th adjustment time, the starting adjustment parameter corresponding to the 10th adjustment time is used as the starting adjustment parameter corresponding to the 11th adjustment time; x′=-3, y′=-10, x=11×a=11, substitute into formula (2) to calculate y=15.2, and set the remaining storage time to 15.2 minutes.
[0073] 12. The 12th adjustment time is the 12th calculation
[0074] There is an access behavior between the 12th adjustment moment and the 11th adjustment moment, and there is no access behavior between the 11th adjustment moment and the 10th adjustment moment, and the calculation is changed to growth. At this time, it is necessary to redetermine the starting adjustment parameters (x′, y′). Then, according to the time between the 11th adjustment moment and the 0th adjustment moment (i.e., 11 minutes) and the remaining storage time after adjustment of the storage data to be managed corresponding to the 11th adjustment moment (i.e., 15.2 minutes), the starting adjustment parameters x′=11, y′=15.2 corresponding to the 12th adjustment moment are determined. x=12×a=12, and y=20.9 is calculated by substituting into formula (2), which is greater than the configured third preset time b (20 minutes). Then, the remaining storage time is set to 20 minutes according to the third preset time b.
[0075] 13. The 13th adjustment time is the 13th calculation
[0076] If there is no access behavior between the 13th adjustment time and the 12th adjustment time and there is an access behavior between the 12th adjustment time and the 11th adjustment time, then there is attenuation at this time. According to the time length between the 12th adjustment time and the 0th adjustment time m=12×a=12, n=the remaining storage time length 20 of the storage data to be managed after adjustment corresponding to the 11th adjustment time, the preset storage time length peak e and the first preset time length f, it is calculated that x′=12–10=2, y′=20–30=-10, x=13×a=13, and y=19.7 is calculated by substituting into formula (2). Then, the remaining storage time length is set to 19.7 minutes.
[0077] 14. The 14th adjustment time is the 14th calculation
[0078] If there is no access behavior between the 14th adjustment time and the 13th adjustment time and there is no access behavior between the 13th adjustment time and the 12th adjustment time, the starting adjustment parameter corresponding to the 13th adjustment time is used as the starting adjustment parameter corresponding to the 14th adjustment time; x′=2, y′=-10, x=14×a=14, substituting into formula (2) to calculate y=18.8, the remaining storage time is set to 18.8 minutes.
[0079] 15. The 15th adjustment time is the 15th calculation
[0080] If there is no access behavior between the 15th adjustment time and the 14th adjustment time and there is no access behavior between the 14th adjustment time and the 13th adjustment time, the starting adjustment parameter corresponding to the 14th adjustment time is used as the starting adjustment parameter corresponding to the 15th adjustment time; x′=2, y′=-10, x=15×a=15 are still substituted into formula (2) to calculate y=17.3, and the remaining storage time is set to 17.3 minutes.
[0081] 16. The 16th adjustment time is the 16th calculation
[0082] If there is no access behavior between the 15th adjustment time and the 14th adjustment time and there is no access behavior between the 14th adjustment time and the 13th adjustment time, the starting adjustment parameter corresponding to the 15th adjustment time is used as the starting adjustment parameter corresponding to the 16th adjustment time; x′=2, y′=-10, x=16×a=16 are still substituted into formula (2) to calculate y=15.2, and the remaining storage time is set to 15.2 minutes.
[0083] 17. The 17th adjustment time is the 17th calculation
[0084] If there is no access behavior between the 17th adjustment time and the 16th adjustment time and there is no access behavior between the 16th adjustment time and the 15th adjustment time, the starting adjustment parameter corresponding to the 16th adjustment time is used as the starting adjustment parameter corresponding to the 17th adjustment time; x′=2, y′=-10, x=17×a=17, substituting into formula (2) to calculate y=12.5, the remaining storage time is set to 12.5 minutes.
[0085] 18. The 18th adjustment time is the 18th calculation
[0086] If there is no access behavior between the 18th adjustment time and the 17th adjustment time and there is no access behavior between the 17th adjustment time and the 16th adjustment time, the starting adjustment parameter corresponding to the 17th adjustment time is used as the starting adjustment parameter corresponding to the 18th adjustment time; x′=2, y′=-10, x=18×a=18, substituting into formula (2) to calculate y=9.2, the remaining storage time is set to 9.2 minutes.
[0087] 19. The 19th adjustment time is the 19th calculation
[0088] If there is no access behavior between the 19th adjustment time and the 18th adjustment time and there is no access behavior between the 18th adjustment time and the 17th adjustment time, the starting adjustment parameter corresponding to the 18th adjustment time is used as the starting adjustment parameter corresponding to the 19th adjustment time; x′=2, y′=-10, x=19×a=19, substituting into formula (2) to calculate y=5.3, the storage duration is set to 5.3 minutes.
[0089] 20. The 20th adjustment time is the 20th calculation
[0090] If there is no access behavior between the 20th adjustment time and the 19th adjustment time and there is no access behavior between the 19th adjustment time and the 18th adjustment time, the starting adjustment parameter corresponding to the 19th adjustment time is used as the starting adjustment parameter corresponding to the 20th adjustment time; x′=2, y′=-10, x=20×a=20, substituting into formula (2) to calculate y=0.8, the remaining storage time is set to 0.8 minutes.
[0091] 21. The 21st adjustment time is the 21st calculation
[0092] This adjustment moment is 1 minute away from the 20th adjustment moment, and the remaining storage time of the 20th adjustment moment is 0.8 minutes, which is 1 minute less than the adjacent adjustment moment. At this time, the data has been naturally cleared and does not need to be calculated again.
[0093] The above 21 calculations are the calculation results of the complete life cycle of the storage data to be managed after it is stored.
[0094] Step S230: If the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero, the storage data to be managed is deleted from the database.
[0095] In order to clean up the storage space of the Redis database in time, when the calculated remaining storage time is 0 or less than 0, the relevant storage data to be managed in the Redis database is directly deleted to free up storage space.
[0096] Figure 4 This is a data time curve diagram of a data storage method provided by an embodiment of the present invention, taking the Redis database as an example. Figure 4 As shown, line 1 represents the linear attenuation rule of the prior art solution, lines 2, 3 and 4 respectively represent the storage time adjustment change curves of the storage data to be managed in different scenarios in this embodiment, the X-axis represents natural time, the Y-axis represents the remaining storage time of the storage data to be managed, each small grid on the X-axis represents an adjustment interval, and each adjustment interval corresponds to two adjustment moments. In this embodiment, the remaining storage time of the storage data to be managed is dynamically adjusted, wherein 30 is the third preset time b, and the unit of the storage time peak in the figure can be specifically minutes.
[0097] like Figure 4 As shown, line 1 represents the default linear decay rule of the temporary data storage time of the Redis database. As time goes by, after the storage time is reached, it will be cleared from the Redis database. To access it again, you need to penetrate the relational database again to obtain the data.
[0098] The curves of line 2, line 3 and line 4 overlap in the time interval [0, 1], and the curves of line 3 and line 4 also overlap in the time interval [1, 2].
[0099] Line 2 indicates that before the remaining storage time of the stored data to be managed is adjusted to the configured third preset time (for example, 30 minutes), since no user accesses the stored data, the remaining storage time begins to decay until it is cleared from the Redis database to release storage space.
[0100] Line 4 indicates that after the storage data to be managed is adjusted to the third preset time, it maintains the third preset time for a period of time and then starts to decay. Since no user has accessed the storage data, it decays multiple times until it is cleared from the Redis database, releasing storage space.
[0101] Line 3 indicates that the remaining storage time of the storage data to be managed has decayed after being adjusted to the third preset time. However, since another user accesses the storage data later, the remaining storage time begins to increase again. After reaching the third preset time again, it continues to remain at the third preset time. In other words, due to the continuous access of the user, the remaining storage time has remained at the third preset time and has not been deleted from the Redis database.
[0102] Lines 2 and 4 in the figure can quickly release storage space; line 3 can effectively reduce the number of times the relational database is penetrated.
[0103] The method of this embodiment is adopted, by filtering out the storage data to be managed from the database, and setting multiple adjustment moments; at the tth adjustment moment, according to the user's access behavior to the storage data to be managed, the remaining storage time of the storage data to be managed is adjusted, where t is greater than 1; if the remaining storage time of the storage data to be managed after adjustment is less than or equal to zero, the storage data to be managed is deleted from the database. The present invention does not store permanent data but stores temporary data, eliminating the possibility of storage space being permanently occupied; by setting multiple adjustment moments, the remaining storage time of the storage data to be managed is adjusted according to whether the storage data to be managed is accessed by a user, so that temporary data is not stored at a fixed time, and the remaining storage time of the storage data to be managed is dynamically extended if there is user access, which can effectively reduce the number of queries to the database, and if there is no user access, the remaining storage time of the storage data to be managed is dynamically shortened or the storage data to be managed is deleted, which can achieve the purpose of quickly releasing space, improve storage resource utilization, and enhance user experience.
[0104] Figure 5 FIG. 2 is a schematic diagram showing a structure of an embodiment of a data storage device of the present invention. Figure 5 As shown, the device includes: an initial module 510, an adjustment module 520 and a data processing module 530.
[0105] The initial module 510 is used to filter out the storage data to be managed from the database and set multiple adjustment times.
[0106] In an optional manner, the database includes a memory storage type database; the initial module 510 is further used to: filter out storage data with a data size greater than a preset threshold from the memory storage type database as storage data to be managed.
[0107] The adjustment module 520 is used to adjust the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed at the t-th adjustment time, where t is greater than 1.
[0108] In an optional manner, the adjustment module 520 is further used to: determine the starting adjustment parameter corresponding to the tth adjustment moment based on the user's access behavior to the storage data to be managed; calculate the remaining storage time of the storage data to be managed after adjustment corresponding to the tth adjustment moment based on the starting adjustment parameter, the preset storage time peak, the first preset time, and the time between the tth adjustment moment and the 0th adjustment moment; wherein the 0th adjustment moment is the initial storage moment of the storage data to be managed.
[0109] In an optional manner, the adjustment module 520 is further used to determine the starting adjustment parameters corresponding to the tth adjustment moment based on whether the user has any access behavior for the storage data to be managed between the tth adjustment moment and the t-1th adjustment moment and between the t-1th adjustment moment and the t-2th adjustment moment.
[0110] In an optional manner, the adjustment module 520 is further used to: if there is an access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is an access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, or, if there is no access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is no access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, then use the starting adjustment parameter corresponding to the t-1-th adjustment moment as the starting adjustment parameter corresponding to the t-th adjustment moment; if there is no access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is an access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, then according to the t-1-th adjustment moment The starting adjustment parameter corresponding to the tth adjustment moment is determined based on the duration between the tth adjustment moment and the 0th adjustment moment, the remaining storage duration of the storage data to be managed after adjustment corresponding to the t-1th adjustment moment, the preset storage duration peak value and the first preset duration; if there is an access behavior between the tth adjustment moment and the t-1th adjustment moment and there is no access behavior between the t-1th adjustment moment and the t-2th adjustment moment, the starting adjustment parameter corresponding to the tth adjustment moment is determined based on the duration between the t-1th adjustment moment and the 0th adjustment moment and the remaining storage duration of the storage data to be managed after adjustment corresponding to the t-1th adjustment moment; wherein, the starting adjustment parameter corresponding to the 1st adjustment moment is a preset parameter.
[0111] In an optional manner, the plurality of adjustment moments are set every second preset time period starting from the initial storage moment of the storage data to be managed.
[0112] In an optional manner, the adjustment module 520 is further used to: determine whether the remaining storage time of the storage data to be managed after adjustment exceeds a third preset time; if so, use the third preset time as the remaining storage time of the storage data to be managed after adjustment.
[0113] The data processing module 530 is configured to delete the storage data to be managed from the database if the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero.
[0114] The device of this embodiment is used to filter out the storage data to be managed from the database and set multiple adjustment moments; at the tth adjustment moment, the remaining storage time of the storage data to be managed is adjusted according to the user's access behavior to the storage data to be managed, where t is greater than 1; if the remaining storage time of the storage data to be managed after adjustment is less than or equal to zero, the storage data to be managed is deleted from the database. The present invention does not store permanent data but stores temporary data, eliminating the possibility of storage space being permanently occupied; by setting multiple adjustment moments, the remaining storage time of the storage data to be managed is adjusted according to whether the storage data to be managed is accessed by a user, so that temporary data is not stored at a fixed time. If there is user access, the remaining storage time of the storage data to be managed is dynamically extended, which can effectively reduce the number of queries to the database. If there is no user access, the remaining storage time of the storage data to be managed is dynamically shortened or the storage data to be managed is deleted, which can achieve the purpose of quickly releasing space, improve storage resource utilization, and enhance user experience.
[0115] An embodiment of the present invention provides a non-volatile computer storage medium, wherein the computer storage medium stores at least one executable instruction, and the computer executable instruction can execute a data storage method in any of the above method embodiments.
[0116] The executable instructions may be specifically used to cause the processor to perform the following operations:
[0117] Filter the storage data to be managed from the database and set multiple adjustment times;
[0118] At the tth adjustment time, the remaining storage duration of the storage data to be managed is adjusted according to the user's access behavior to the storage data to be managed, where t is greater than 1;
[0119] If the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero, the storage data to be managed is deleted from the database.
[0120] Figure 6 The schematic diagram of the structure of the computing device embodiment of the present invention is shown. The specific embodiment of the present invention does not limit the specific implementation of the computing device.
[0121] like Figure 6 As shown, the computing device may include:
[0122] Processor, Communications Interface, Memory, and Communications Bus.
[0123] Wherein: the processor, the communication interface, and the memory communicate with each other through the communication bus. The communication interface is used to communicate with other devices such as a client or other server network elements. The processor is used to execute the program, and specifically can execute the relevant steps of the above-mentioned data storage method embodiment.
[0124] Specifically, the program may include program codes including computer operation instructions.
[0125] The processor may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present invention. The one or more processors included in the server may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0126] The memory is used to store programs. The memory may include a high-speed RAM memory, and may also include a non-volatile memory, such as at least one disk memory.
[0127] The program can be specifically used to cause the processor to perform the following operations:
[0128] Filter the storage data to be managed from the database and set multiple adjustment times;
[0129] At the tth adjustment time, the remaining storage duration of the storage data to be managed is adjusted according to the user's access behavior to the storage data to be managed, where t is greater than 1;
[0130] If the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero, the storage data to be managed is deleted from the database.
[0131] The algorithm or display provided here is not inherently related to any specific computer, virtual system or other equipment. Various general systems can also be used together with the teaching based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the embodiment of the present invention is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the present invention described here, and the description of the above specific language is for disclosing the best mode of the present invention.
[0132] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0133] Similarly, it should be understood that in order to streamline the present invention and aid in understanding one or more of the various inventive aspects, in the above description of exemplary embodiments of the present invention, the various features of the embodiments of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, this disclosed method should not be interpreted as reflecting the following intention: that the claimed invention requires more features than the features explicitly recited in each claim. More specifically, as reflected in the claims below, inventive aspects lie in less than all the features of the individual embodiments disclosed above. Therefore, the claims that follow the specific embodiment are hereby expressly incorporated into the specific embodiment, with each claim itself serving as a separate embodiment of the present invention.
[0134] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0135] In addition, those skilled in the art will appreciate that, although some embodiments herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0136] The various component embodiments of the present invention can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components according to embodiments of the present invention. The present invention can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the present invention can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0137] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names. The steps in the above embodiments, unless otherwise specified, should not be understood as limitations on the order of execution.
Claims
1. A data storage method, characterized in that: include: Filter the storage data to be managed from the database and set multiple adjustment times; At the tth adjustment time, adjusting the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed, where t is greater than 1; If the adjusted remaining storage duration of the storage data to be managed is less than or equal to zero, deleting the storage data to be managed from the database; The step of adjusting the remaining storage duration of the storage data to be managed at the tth adjustment time according to the user's access behavior to the storage data to be managed includes: Determining a starting adjustment parameter corresponding to the tth adjustment moment according to the user's access behavior to the storage data to be managed; The remaining storage time of the storage data to be managed after adjustment corresponding to the tth adjustment time is calculated according to the starting adjustment parameter, the preset storage time peak value, the first preset time, and the time between the tth adjustment time and the 0th adjustment time; wherein the 0th adjustment time is the initial storage time of the storage data to be managed; The formula for calculating the remaining storage time is: Among them, (x ′ ,y ′ ) is the starting adjustment parameter corresponding to the tth adjustment moment, e is the preset storage duration peak, f is the first preset duration, x represents the duration between the tth adjustment moment and the 0th adjustment moment, and y is the remaining storage duration after this adjustment.
2. The method according to claim 1, characterized in that The database includes a memory storage type database; The step of filtering out the storage data to be managed from the database further comprises: The storage data with a data size greater than a preset threshold is filtered out from the memory storage database as the storage data to be managed.
3. The method according to claim 1, characterized in that The step of determining the starting adjustment parameter corresponding to the tth adjustment time according to the user's access behavior to the storage data to be managed also includes: The starting adjustment parameter corresponding to the tth adjustment time is determined according to whether the user has any access behavior for the storage data to be managed between the tth adjustment time and the t-1th adjustment time and between the t-1th adjustment time and the t-2th adjustment time.
4. The method according to claim 3, characterized in that The determining of the starting adjustment parameter corresponding to the tth adjustment time according to whether the user has access behavior for the storage data to be managed between the tth adjustment time and the t-1th adjustment time and between the t-1th adjustment time and the t-2th adjustment time includes: If there is an access behavior between the t-th adjustment time and the t-1-th adjustment time and an access behavior between the t-1-th adjustment time and the t-2-th adjustment time, or if there is no access behavior between the t-th adjustment time and the t-1-th adjustment time and no access behavior between the t-1-th adjustment time and the t-2-th adjustment time, then the starting adjustment parameter corresponding to the t-1-th adjustment time is used as the starting adjustment parameter corresponding to the t-th adjustment time; If there is no access behavior between the t-th adjustment moment and the t-1-th adjustment moment and there is access behavior between the t-1-th adjustment moment and the t-2-th adjustment moment, determine the starting adjustment parameter corresponding to the t-th adjustment moment according to the duration between the t-1-th adjustment moment and the 0th adjustment moment, the remaining storage duration of the storage data to be managed after adjustment corresponding to the t-1-th adjustment moment, the preset storage duration peak value and the first preset duration; If there is an access behavior between the t-th adjustment time and the t-1-th adjustment time and there is no access behavior between the t-1-th adjustment time and the t-2-th adjustment time, then according to the duration between the t-1-th adjustment time and the 0th adjustment time and the remaining storage duration of the stored data to be managed corresponding to the t-1-th adjustment time after adjustment, determine the starting adjustment parameter corresponding to the t-th adjustment time; Among them, the initial adjustment parameter corresponding to the first adjustment moment is the preset parameter.
5. The method according to any one of claims 1 to 4, characterized in that: The plurality of adjustment moments are set at intervals of a second preset time period starting from the initial storage moment of the storage data to be managed.
6. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: adjusting the remaining storage duration of the stored data to be managed according to the user's access behavior to the stored data to be managed at the tth adjustment time. Determining whether the adjusted remaining storage time of the stored data to be managed exceeds a third preset time; If so, the third preset duration is used as the adjusted remaining storage duration of the stored data to be managed.
7. A data storage device, characterized in that: include: The initial module is used to filter the storage data to be managed from the database and set multiple adjustment moments; an adjustment module, configured to adjust the remaining storage duration of the storage data to be managed according to the user's access behavior to the storage data to be managed at the tth adjustment time, wherein t is greater than 1; A data processing module, configured to delete the stored data to be managed from the database if the adjusted remaining storage duration of the stored data to be managed is less than or equal to zero; Wherein, the adjustment module is further used for: Determining a starting adjustment parameter corresponding to the tth adjustment moment according to the user's access behavior to the storage data to be managed; The remaining storage time of the storage data to be managed after adjustment corresponding to the tth adjustment time is calculated according to the starting adjustment parameter, the preset storage time peak value, the first preset time, and the time between the tth adjustment time and the 0th adjustment time; wherein the 0th adjustment time is the initial storage time of the storage data to be managed; The formula for calculating the remaining storage time is: Among them, (x ′ ,y ′ ) is the starting adjustment parameter corresponding to the tth adjustment moment, e is the preset storage duration peak, f is the first preset duration, x represents the duration between the tth adjustment moment and the 0th adjustment moment, and y is the remaining storage duration after this adjustment.
8. A computing device, characterized in that include: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute an operation corresponding to a data storage method according to any one of claims 1-6.
9. A computer storage medium, characterized in that The storage medium stores at least one executable instruction, and the executable instruction enables the processor to execute an operation corresponding to a data storage method as described in any one of claims 1-6.
