A short link generation method, device and medium
By combining the MurmurHash algorithm with the time dimension of the business domain, the problems of poor performance in short link generation and data security are solved, and efficient and secure short link generation and management are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- PEOPLE'S INSURANCE COMPANY OF CHINA
- Filing Date
- 2023-05-29
- Publication Date
- 2026-05-12
AI Technical Summary
Existing methods for generating short links suffer from poor performance, are prone to data leakage, and lack data lifecycle governance, resulting in high duplication rates and insufficient security.
The MurmurHash algorithm is used to generate unordered and irregular short link codes. Data is stored in combination with business domain and time dimensions. The mapping relationship is managed through Redis database, and expired data is cleaned up regularly to achieve lifecycle governance of short links.
It reduces the duplication rate and number of conversions of short links, improves generation performance, prevents customer information leakage, expands the scope of use of short links, and realizes data lifecycle management.
Smart Images

Figure CN116738085B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of link conversion, and more particularly to a method, apparatus, and medium for generating short links. Background Technology
[0002] When browsing the internet, if you're using a browser, the browser will display a URL, either short or long, in the address bar of each webpage. These URLs are generally called links, or long links. While the HTTP protocol specification doesn't impose a length limit on links, most browsers and web servers do specify the length of requested links.
[0003] In certain scenarios, the use of long links can be inadequate or even unusable. For example, in the SMS industry, when conducting marketing campaigns using SMS, it's necessary to send campaign links to target users. Long links take up too much text in the message, making the overall message too long. Due to international standards, each SMS message has a maximum length limit; if the length is too long, it may fail to send or require sending in multiple messages. Another example is the rise of social media platforms like Weibo, where more people like to express their opinions. However, Weibo initially limited the length of individual posts, leading to problems with users sharing excessively long links.
[0004] Therefore, it is necessary to solve the above problems by converting long links into short links, making the links look more concise and improving the user experience.
[0005] The common methods for generating short links from long links are as follows:
[0006] 1. Short links are generated using one-way hash functions. This involves using one-way hash algorithms such as MD5 to calculate the hash value of the long link, then Base64 encoding the hash value, truncating the number of bits according to the required length of the short link, and finally saving the correspondence between long and short links in the database.
[0007] 2. Self-increasing short links: This involves maintaining a self-increasing binary number, then Base64 encoding this number to obtain a series of short links, and saving the correspondence between long and short links in the database.
[0008] The main drawbacks of existing technologies are as follows:
[0009] 1. Single-chain hash algorithms such as MD5 have a high hash collision rate and poor random distribution characteristics, resulting in a high repetition rate of generated short links. If a link is repeated, it needs to be called multiple times to resolve the issue, leading to poor performance.
[0010] 2. Short links generated by self-incrementing algorithms are predictable and can be guessed blindly. Since some short links may ultimately lead to pages displaying customer information, there is a risk of customer information data leakage.
[0011] 3. The lack of data lifecycle governance in the data management of the correspondence between long and short links indirectly leads to a high rate of duplicate short links. Summary of the Invention
[0012] This invention provides a method, device, and medium for generating short links, which solves the problems of poor performance, easy data leakage, and lack of data lifecycle governance in existing short links.
[0013] A method for generating short links, comprising:
[0014] Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship.
[0015] Step 2: If it does not exist, convert the long link into short link code according to the short link encoding generation rules and the table ending rules;
[0016] Step 3: Query the database to see if a record of the short link code already exists;
[0017] Step 4:
[0018] Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller;
[0019] Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0020] In one embodiment of the present invention, the step of converting the long link into a short link code according to the short link code generation rule specifically includes: hashing the long link based on the MurmurHash algorithm to obtain a hash value; encoding the hash value using Base62 to determine a 6-digit base-62 string as the first 6 digits of the short link code; querying the business domain routing table according to the long link to short link conversion request to determine the short link storage table identifier; locating the year cursor table according to the short link storage table identifier and the table placement rule; and concatenating the last digit of the table name of the year cursor table with the first 6 digits of the short link code to obtain a 7-digit short link code.
[0021] In one embodiment of the present invention, the method further includes: when the number of repetitions exceeds a preset value n, returning a message indicating that the short link generation failed.
[0022] In one embodiment of the present invention, the step of locating the year cursor table according to the short link storage table identifier and the table placement rules specifically includes: determining the short link storage table to which the short link belongs based on the short link storage table identifier; determining the year table to which the short link belongs in the short link storage table based on the current year; obtaining the value from the key-value pair based on the request ID in the long link to short link request; and locating the year cursor table to which the short link belongs in the year table based on the value.
[0023] In one embodiment of the present invention, before storing the long link and the short link encoding into the database, the method further includes: dividing the short link storage table under the same business domain into 36 year cursor tables; dividing the 36 year cursor tables into 6 parts, each part being the year table to be operated on for the corresponding year; and identifying the last character of the table name of the 36 year cursor tables with AZ and 0-9 respectively.
[0024] In one embodiment of the present invention, determining the year table to which the short link belongs in the short link storage table based on the current year specifically includes: using the lifecycle time of each short link storage table as the remainder; and using the product system launch year as the minuend.
[0025] The number of years in the year table is determined using the following formula:
[0026] The year number = ((current year - minuend) % remainder) + 1
[0027] The year table is determined based on the year number mentioned above.
[0028] In one embodiment of the present invention, the step of locating the year cursor table to which the short link in the year table belongs based on the value value specifically includes: triggering the current value in the key-value pair to increment based on the long link to short link request ID, and obtaining the incremented value value;
[0029] The position of the year vernier table is determined using the following formula:
[0030] The value of N in the Nth year cursor table = value%6+1;
[0031] Position the year cursor table based on the N value.
[0032] In one embodiment of the present invention, generating a short link based on the short link code specifically includes: obtaining a short link prefix path in the business domain routing table that is in the same business domain as the short link code; and concatenating the short link code and the short link prefix path to obtain a short link.
[0033] A device for generating short links, comprising:
[0034] At least one processor; and,
[0035] A memory that is communicatively linked to the at least one processor via a bus; wherein,
[0036] The memory stores instructions executable by the at least one processor, which are executed to perform:
[0037] Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship.
[0038] Step 2: If it does not exist, convert the long link into short link code according to the short link encoding generation rules and the table ending rules;
[0039] Step 3: Query the database to see if a record of the short link code already exists;
[0040] Step 4:
[0041] Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller;
[0042] Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0043] A non-volatile storage medium storing computer-executable instructions, which are executed by a processor to perform the following steps:
[0044] Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship.
[0045] Step 2: If it does not exist, convert the long link into short link code according to the short link encoding generation rules and the table ending rules;
[0046] Step 3: Query the database to see if a record of the short link code already exists;
[0047] Step 4:
[0048] Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller;
[0049] Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0050] This invention provides a method, device, and medium for generating short links, which has at least the following advantages: By storing the mapping relationships of long and short links for different years within the same business domain in different year cursor tables, the expired year data can be periodically dumped and cleaned up, and the cleaned tables can be reused, based on the short link data lifecycle of the business domain, to achieve the purpose of historical data migration backup and data lifecycle management; by combining the hash value with the table name of the year cursor table to generate short link codes, the duplication rate of short link codes and the number of repeated conversions are reduced; by determining the business domain to which the short link belongs based on different business domain identifiers, the scope of data use can be increased, so the same 7-bit short link code can be provided to different business domains, increasing the reuse of short link codes. Attached Figure Description
[0051] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:
[0052] Figure 1 A schematic diagram illustrating the steps of a method for generating short links according to an embodiment of the present invention;
[0053] Figure 2 This is a schematic diagram of the long link to short link conversion process provided in an embodiment of the present invention;
[0054] Figure 3 This is a schematic diagram of the short link to long link conversion process provided in an embodiment of the present invention;
[0055] Figure 4 This is a schematic diagram of a short link generation device provided in an embodiment of the present invention. Detailed Implementation
[0056] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be described clearly and completely below in conjunction with specific embodiments. Obviously, the described embodiments are only a part of the embodiments of this invention, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0057] It should be noted that those skilled in the art will understand, explicitly and implicitly, that the embodiments described in this invention can be combined with other embodiments without conflict. Unless otherwise defined, the technical or scientific terms used in this invention should be understood in their ordinary sense by those skilled in the art. The terms "a," "an," "an," "the," etc., used in this invention do not indicate quantity limitation and can represent singular or plural. The terms "comprising," "including," "having," and any variations thereof used in this invention are intended to cover non-exclusive inclusion; the terms "first," "second," "third," etc., used in this invention are merely to distinguish similar objects and do not represent a specific ordering of objects.
[0058] To address the shortcomings of existing technologies, this invention proposes a method, device, and medium for generating short links. It generates unordered, irregular, and low-collision-rate short links based on the MurmurHash algorithm. Furthermore, it controls the data volume of a single table within a short link by considering both business domain and time dimensions, enabling the reuse of data from the same short link across different business domains and achieving lifecycle management of the short link data. The details are described below.
[0059] Figure 1 This is a schematic diagram illustrating the steps of a method for generating short links according to an embodiment of the present invention, which may include the following steps:
[0060] S110: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship.
[0061] Specifically, to avoid unknown system problems caused by duplication, idempotency checks are performed before converting long links to short links. The system queries the Redis database to check if the short link exists based on the long link; if it does, it directly returns a successful short link generation. This application uses a Redis database to store the long-short link mapping relationship. Redis database has good performance, and a single machine can support 100,000+ requests, which is sufficient to handle most business scenarios.
[0062] S120: If it does not exist, convert the long link into a short link code according to the short link encoding generation rules and the table ending rules.
[0063] In one embodiment of the present invention, converting a long link into a short link code according to the short link code generation rules specifically includes: hashing the long link based on the MurmurHash algorithm to obtain a hash value; encoding the hash value using Base62 to determine a 6-digit base-62 string as the first 6 digits of the short link code; querying the business domain routing table according to the long link to short link conversion request to determine the short link storage table identifier; locating the year cursor table according to the short link storage table identifier and the table placement rules; and concatenating the last digit of the year cursor table name with the first 6 digits of the short link code to obtain a 7-digit short link code.
[0064] Specifically, the rules for generating short link encodings are as follows:
[0065] The first six characters: Based on the long link, the hash value is calculated using Murmurhash, and then the hash value is converted into a six-character string in base-62. If it is less than six characters, it is padded to six characters.
[0066] The last character: After determining the year cursor table to which the short link belongs according to the table rules, extract the last character of the table name.
[0067] If the database does not contain a corresponding long-short link mapping, a request to convert a long link to a short link is generated, and the corresponding execution action is triggered based on this conversion request. For example... Figure 2 The diagram shows the process of converting a long link to a short link. When a request to convert a long link to a short link is triggered, the long link is hashed using the MurmurHash algorithm to obtain a hash value.
[0068] Compared to encryption algorithms such as MD5 and SHA, MurmurHash is a non-encryption hash function suitable for general hash retrieval operations. Compared to other popular hash functions, it outperforms algorithms such as MD5 and SHA. For keys with strong regularity, MurmurHash's random distribution characteristics perform better, making it suitable for scenarios where long links are converted into short links. It can effectively reduce the collision rate of short links, and the generated short links are unpredictable, preventing the leakage of customer data.
[0069] The number hashed using the MurmurHash algorithm is in decimal. To further shorten the hash value, it can be converted to base-62 using Base62 encoding, thus shortening the hash value length and obtaining a six-digit code in the short link suffix. If the converted code is less than six digits, an arbitrary number (usually 0) is added in front of it to make it six digits.
[0070] Since hash operations can lead to hash collisions, the probability of collisions increases with large datasets. To better accommodate hash value collisions and avoid repeated calculations due to collisions, this application combines the hash value with the table name to obtain a short link code. This increases the reusability of the hash value and expands the scope of data usage. The following explains how to determine the last digit of the short link code.
[0071] The request to convert a long link to a short link includes an identifier of the business domain to which the long link belongs. Based on this business domain identifier, the corresponding short link storage table identifier is queried from the business domain routing table. The business domain routing table determines the storage location of the long-short link mapping relationship.
[0072] For example, Table 1 shows data from a business domain routing table:
[0073]
[0074]
[0075] As can be seen from Table 1, the business domain identifier and the short link storage table identifier correspond to each other. After obtaining the business domain identifier in the request to convert a long link to a short link, the short link storage table identifier can be obtained by matching the identifier in the business domain routing table.
[0076] In one embodiment of the present invention, before storing the long links and short links in the database, the short link storage table under the same business domain is divided into 36 year cursor tables; the 36 year cursor tables are divided into 6 parts, each part being the year table to be operated on for the corresponding year; the last character of the table name of the 36 year cursor tables is identified by AZ and 0-9 respectively.
[0077] Specifically, after obtaining the short-link storage table identifier, the short-link storage table can be located. The short-link storage table is a data storage set within the same business domain. To store the long-short link mapping relationship systematically, this data storage set needs to be partitioned according to the partitioning rules. The partitioning rules are as follows:
[0078] For data storage in the same business area, 36 year cursor tables are created. The last character of the table name of each year cursor table is identified by AZ and 0-9. The 36 tables are divided into 6 parts according to 6 years, and each part is the year table that needs to be operated on for each year.
[0079] For example, based on the data in Table 1 above, if the business domain is C-end order processing, the corresponding business domain identifier is CI, then the short link storage table identifier is CI, and the corresponding short link storage table name is shortUrl_CI. The 36 tables are then divided evenly over 6 years, and the tables requiring operations for each year are as follows (for ease of reading and differentiation, only the last character of the cursor table name for each year is listed):
[0080] Year 1: A, B, C, D, E, F
[0081] Second year: G, H, I, J, K, L
[0082] Third year: M, N, O, P, Q, R
[0083] Fourth year: S, T, U, V, W, X
[0084] Fifth year: Y, Z, 0, 1, 2, 3
[0085] Year 6: 4, 5, 6, 7, 8, 9.
[0086] In one embodiment of the present invention, locating the year cursor table based on the short link storage table identifier and the table placement rules specifically includes: determining the short link storage table to which the short link belongs based on the short link storage table identifier; determining the year table to which the short link belongs in the short link storage table based on the current year; obtaining the value from the key-value pair based on the request ID in the long link to short link conversion request; and locating the year cursor table to which the short link belongs in the year table based on the value.
[0087] Specifically, the table placement rules are as follows:
[0088] (1) Determine the year table:
[0089] Define the remainder as 6 (i.e., the lifecycle time of each domain table data), and the minuend as the year the system went live. The algorithm is as follows:
[0090] The year number = ((current year - minuend)% remainder) + 1;
[0091] Here, % represents the remainder operation.
[0092] (2) Positioning table (year vernier table):
[0093] Redis maintains a key-value pair to record the request ID of each long-connection to short-connection request, where the value is a number. The INCR method retrieves the auto-incrementing sequence (the database switchover sequence in case of Redis failure). The algorithm is as follows:
[0094] The value of N in the Nth table of the current year = value%6+1;
[0095] Here, % represents the remainder operation.
[0096] In one embodiment of the present invention, determining the year table to which a short link belongs in the short link storage table based on the current year specifically includes: using the lifecycle time of each short link storage table as the remainder; and using the year the product system went live as the minuend.
[0097] The number of years in the year table is determined using the following formula:
[0098] The year number = ((current year - minuend) % remainder) + 1
[0099] The year table is determined based on the year number.
[0100] Specifically, the long and short link mapping relationships for different years within the same business domain are stored in different year cursor tables. Before locating a year cursor table, it is necessary to first locate the year table to which it belongs.
[0101] For example, based on the data in the aforementioned embodiments, if the current year is 2020, and the lifecycle of the short-linked storage table for each domain is defined as 6 years, then the remainder is 6. If the product launch year is 2020, then the minuend is 2020.
[0102] According to the formula
[0103] The year number = ((2020-2020)%6) + 1
[0104] The result is 1, which means that the current cursor table to be accessed is the first year's cursor table. Therefore, the tables to be operated on are shortUrl_CI_A, shortUrl_CI_B, shortUrl_CI_C, shortUrl_CI_D, shortUrl_CI_E, and shortUrl_CI_F.
[0105] In one embodiment of the present invention, locating the year cursor table to which the short link belongs in the year table according to the value value specifically includes: triggering the current value in the key-value pair to be incremented according to the long link to short link request ID, so as to obtain the incremented value value;
[0106] The position of the year vernier table is determined using the following formula:
[0107] The value of N in the Nth year cursor table = value%6+1;
[0108] Position the year cursor table based on the N value.
[0109] Specifically, to ensure that the long and short link mappings are evenly distributed across the year cursor table, a key-value pair is maintained in the Redis database.<key,value> This is used to record the request ID of each long-connection to short-connection request. The value is a number. When a request ID is triggered, the Redis INCR command (Redis crash switch database auto-increment sequence) increments the numeric value stored in the key by one, and the cursor table of the year is located based on the value.
[0110] For example, the first year cursor table shortUrl_CI_A for the first year, the second year cursor table shortUrl_CI_B for the first year, the first year cursor table shortUrl_CI_G for the second year, and so on.
[0111] After locating the year cursor table, the last digit of its table name is extracted and added to the end of the six-digit hash value to obtain a seven-digit short link code. This short link code and the long link form a long-short link mapping relationship, which can be stored in the data storage set corresponding to this business domain.
[0112] By storing the long and short link mapping relationships for different years within the same business domain in different year cursor tables, it is possible to periodically dump and clean up expired year data and reuse the cleaned tables, based on the lifecycle of short link data in the business domain, in order to achieve the purpose of historical data migration backup and lifecycle management.
[0113] S130: Query the database to see if a record with a short link code already exists.
[0114] To avoid multiple long links corresponding to a single short link suffix, a unique index can be set for the short link encoding field. When storing data, if an encoding conflict occurs, meaning that the data table to be stored already contains a long-short link mapping relationship for that encoding, then this data cannot be added to the database.
[0115] S140: If it does not exist, generate a short link based on the short link code. If the short link generation is successful, store the long link and the short link code in the database and return the short link to the caller.
[0116] In one embodiment of the present invention, generating a short link based on a short link code specifically includes: obtaining a short link prefix path in the business domain routing table that is the same as the short link code; and concatenating the short link code and the short link prefix path to obtain a short link.
[0117] Specifically, if the generated short link code does not exist in the corresponding year cursor table in the database, the short link code is concatenated with the corresponding short link prefix path in the business domain routing table to obtain the short link and return it to the caller.
[0118] When a user accesses a webpage via a shortened link, the system determines the long link by looking up the long-short link mapping in the database, and then accesses the original webpage using the long link. For example... Figure 3 The diagram illustrates the process of converting a short link to a long link. After obtaining the short link domain name, the business domain to which the short link belongs is determined from the prefix path of the short link, such as CI. The last digit of the 7-digit short link code is used to determine the identifier of the year cursor table where the long-short link mapping relationship is stored. The year cursor table where the long-short link mapping relationship is located is determined by the business domain and the year cursor table identifier, for example, the year cursor table named prptshorturl_CI_A. The long-short link mapping relationship is queried based on the 7-digit short link code, and the long link is returned.
[0119] S142: If it exists, add m random numbers to the end of the long link to generate a new long link. Repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0120] In one embodiment of the present invention, when the number of repetitions exceeds a preset value n, a message indicating that short link generation failed is returned.
[0121] Specifically, to avoid wasting resources due to repeated generation over a long period of time, the number of repetitions can be preset, such as 10 times, until the short link is successfully generated. If the short link is still not successfully generated after 10 times, a message indicating that the short link generation failed is returned.
[0122] This invention also provides a corresponding short link generation device, such as... Figure 4 As shown, it includes:
[0123] The system includes at least one processor 402, a communication interface 404, a memory 406, and a communication bus 408; wherein the processor 402, the communication interface 404, and the memory 406 communicate with each other through the communication bus 408; the processor 402 can call logical instructions stored in the memory 406 to cause at least one processor 402 to execute:
[0124] Step 1: Query the database to see if the corresponding long-short link mapping exists. If it exists, return the short link based on the long-short link mapping.
[0125] Step 2: If it does not exist, convert the long link into a short link code according to the short link encoding generation rules and the table ending rules;
[0126] Step 3: Check the database to see if a record with the short link code already exists;
[0127] Step 4:
[0128] Sub-step 4.1: If it does not exist, generate a short link based on the short link code. If the short link generation is successful, store the long link and the short link code in the database and return the short link to the caller.
[0129] Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0130] Based on the same idea, some embodiments of the present invention also provide media corresponding to the above methods.
[0131] Some embodiments of the present invention provide a storage medium storing computer-executable instructions, which are executed by a processor to perform the following steps:
[0132] Step 1: Query the database to see if the corresponding long-short link mapping exists. If it exists, return the short link based on the long-short link mapping.
[0133] Step 2: If it does not exist, convert the long link into a short link code according to the short link encoding generation rules and the table ending rules;
[0134] Step 3: Check the database to see if a record with the short link code already exists;
[0135] Step 4:
[0136] Sub-step 4.1: If it does not exist, generate a short link based on the short link code. If the short link generation is successful, store the long link and the short link code in the database and return the short link to the caller.
[0137] Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
[0138] The various embodiments in this invention are described in a progressive manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device and medium embodiments are relatively simple in description because they are fundamentally similar to the method embodiments; relevant parts can be referred to the descriptions in the method embodiments.
[0139] The devices, media, and methods provided in the embodiments of the present invention are one-to-one correspondences. Therefore, the devices and media also have similar beneficial technical effects as their corresponding methods. Since the beneficial technical effects of the methods have been described in detail above, the beneficial technical effects of the devices and media will not be repeated here.
[0140] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process method or product 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 or product. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process method or product that includes that element.
[0141] The above are merely embodiments of the present invention and are not intended to limit the invention. Although the present invention has been described in detail above with general descriptions and specific embodiments, modifications or improvements can be made to it, which will be obvious to those skilled in the art. Therefore, all such modifications or improvements made without departing from the spirit of the present invention fall within the scope of protection claimed by the present invention.
Claims
1. A method for generating short links, characterized in that, include: Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship. Step 2: If it does not exist, convert the long link into a short link code according to the short link encoding generation rules and the table ending rules. Specifically, this includes: hashing the long link based on the MurmurHash algorithm to obtain the hash value. The hash value is Base62 encoded to determine a 6-digit base-62 string, which is used as the first 6 digits of the short link code. The business domain routing table is queried according to the long link to short link request to determine the short link storage table identifier. The year cursor table is located according to the short link storage table identifier and the table placement rules. The last digit of the table name of the year cursor table is concatenated with the first 6 digits of the short link code to obtain a 7-digit short link code. Step 3: Query the database to see if a record of the short link code already exists based on the unique index of the short link code; Step 4: Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller; Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
2. The method according to claim 1, characterized in that, The method further includes: If the number of repetitions exceeds the preset value n, a message indicating that short link generation failed will be returned.
3. The method according to claim 1, characterized in that, The step of locating the year cursor table based on the short-linked storage table identifier and the table placement rules specifically includes: The short link storage table to which the short link belongs is determined based on the short link storage table identifier; Determine the year table to which the short link belongs in the short link storage table based on the current year; Retrieve the value from the key-value pair based on the request ID in the long-to-short-link request; The cursor table of the year to which the short link in the year table belongs is located based on the value.
4. The method according to claim 1, characterized in that, Before encoding and storing the long link and the short link into the database, the method further includes: The short-linked storage tables within the same business domain are divided into 36 year cursor tables; Divide the 36 year cursor tables into 6 parts, each part being the year table to be operated on for the corresponding year; The last character of the name of the 36 year vernier tables is identified by AZ and 0-9 respectively.
5. The method according to claim 3, characterized in that, The step of determining the year table to which the short link belongs in the short link storage table based on the current year specifically includes: Use the lifetime of each short-linked storage table as the plural; Use the year the product system went live as the minuend; The number of years in the year table is determined using the following formula: The year number = ((current year - minuend) % remainder) + 1 The year table is determined based on the year number mentioned above.
6. The method according to claim 3, characterized in that, The step of locating the year cursor table to which the short link in the year table belongs based on the value specifically includes: Based on the request ID for converting a long link to a short link, the current value in the key-value pair is incremented to obtain the incremented value. The position of the year vernier table is determined using the following formula: The value of N in the Nth year cursor table = value%6+1; Position the year cursor table based on the N value.
7. The method according to claim 1, characterized in that, The step of generating a short link based on the short link encoding specifically includes: Obtain the short link prefix path in the business domain routing table that is the same as the short link code in the business domain; The short link is obtained by concatenating the short link encoding and the short link prefix path.
8. A device for generating short links, characterized in that, include: At least one processor; as well as, A memory that is communicatively linked to the at least one processor via a bus; wherein, The memory stores instructions executable by the at least one processor, which are executed to perform: Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship. Step 2: If the long link does not exist, convert it into a short link code according to the short link encoding generation rules and table placement rules. Specifically, this includes: hashing the long link using the MurmurHash algorithm to obtain a hash value; encoding the hash value using Base62 to determine a 6-digit base-62 string as the first 6 digits of the short link code; querying the business domain routing table based on the long link to short link conversion request to determine the short link storage table identifier; locating the year cursor table based on the short link storage table identifier and table placement rules; and concatenating the last digit of the year cursor table name with the first 6 digits of the short link code to obtain a 7-digit short link code. Step 3: Query the database to see if a record of the short link code already exists based on the unique index of the short link code; Step 4: Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller; Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.
9. A non-volatile storage medium storing computer-executable instructions, characterized in that, The computer-executable instructions are executed by the processor to perform the following steps: Step 1: Query the database to see if the corresponding long-short link mapping relationship exists. If it exists, return the short link according to the long-short link mapping relationship. Step 2: If it does not exist, convert the long link into a short link code according to the short link encoding generation rules and the table ending rules. Specifically, this includes: hashing the long link based on the MurmurHash algorithm to obtain the hash value. The hash value is Base62 encoded to determine a 6-digit base-62 string, which is used as the first 6 digits of the short link code. The business domain routing table is queried according to the long link to short link request to determine the short link storage table identifier. The year cursor table is located according to the short link storage table identifier and the table placement rules. The last digit of the table name of the year cursor table is concatenated with the first 6 digits of the short link code to obtain a 7-digit short link code. Step 3: Query the database to see if a record of the short link code already exists based on the unique index of the short link code; Step 4: Sub-step 4.1: If it does not exist, generate a short link according to the short link code, confirm that the short link is successfully generated, store the long link and the short link code in the database, and return the short link to the caller; Sub-step 4.2: If it exists, add m random numbers to the end of the long link to generate a new long link; repeat steps 2 to 4 based on the new long link until the short link is successfully generated.