CN111026985A - Method, device and server for generating short link - Google Patents
Method, device and server for generating short link Download PDFInfo
- Publication number
- CN111026985A CN111026985A CN201911215940.1A CN201911215940A CN111026985A CN 111026985 A CN111026985 A CN 111026985A CN 201911215940 A CN201911215940 A CN 201911215940A CN 111026985 A CN111026985 A CN 111026985A
- Authority
- CN
- China
- Prior art keywords
- link
- short link
- short
- long
- characters
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/955—Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]
- G06F16/9558—Details of hyperlinks; Management of linked annotations
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Transfer Between Computers (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a short link generation method which is suitable for being executed in a server, wherein the server is in communication connection with a database, a plurality of data tables are generated in the database, the name of each data table is represented by an m-bit character, and each bit character is a 62-system character code, and the method comprises the following steps: receiving a long chain connection array to be converted, and generating a global unique digital identifier corresponding to each long chain connection based on the long chain connection number in the array; based on the 62-system character codes after the disorder sequence, carrying out 62-system conversion on each digital identifier to obtain a corresponding short chain connection, wherein the short chain connection is represented by n-bit characters, and n is m +4, and the front edge of the characters which are less than n is filled with default characters; and analyzing the first m-bit characters of the short link, determining a data table with the first m-bit characters as a table name, and storing the key value pair into the data table with the short link code as a key and the corresponding long link as a value. The invention also discloses a corresponding short link generation device and a server.
Description
Technical Field
The invention relates to the technical field of computers and science, in particular to a short link generation method, a short link generation device and a short link generation server.
Background
Short links, also known as short addresses, short web addresses, web address shortages, URL shortages, etc., refer to a technology and service on the internet that can provide a very short URL in place of a possibly longer URL. The user may redirect to the original URL when accessing the shortened URL. Most URL shortening services are provided with an API. The URL shortening service is widely used in Twitter and other micro blogs with word count limitation on each message and other social networks.
Since some Twitter-like microblog services have word count limitations (up to 140 words) for each post or message. Some BBS articles exceed 78 characters in a row, which also causes some Telnet and BBS software that automatically add hyperlinks to websites to fail to operate correctly, and therefore needs to achieve the purpose of website shortening through the function of website shortening. The short link also has the function of facilitating the user to memorize and send the website, and the short address can convert the too long website into a substitute website within 15 words.
The short link generation can be realized in two ways, one way is to apply the MD5 algorithm to the long network address to generate a 32-bit string, divide the string into 4 segments, each segment has 1 byte, and cycle the four segments to take 4 bytes. Then, each segment and 0x3fffffff (30 bits 1) are operated, the 30 bits are divided into 6 segments, each 5-bit number is used as the index of the alphabet to obtain a specific character, and the 6-bit character string is obtained in sequence. At the on-line initial stage of the system, the generated long network addresses are few and cannot be repeated, so that the algorithm is simple and effective; but are not suitable for application in large data volume scenarios, repeated short links may occur.
The other method is that the unique character string is generated after the number and the character combination are mapped to a certain degree, and then the short link is stored in a cache and a database. However, the database generally has a large storage capacity, which results in low query performance, and when a cache has a problem, the database is a performance bottleneck. Therefore, it is desirable to provide a more efficient short link processing.
Disclosure of Invention
In view of the above problems, the present invention provides a short link generation method, apparatus and server, in an effort to solve or at least solve the above existing problems.
According to an aspect of the present invention, there is provided a short link generation method, adapted to be executed in a server, the server being in communication connection with a database, the database generating a plurality of data tables, each data table name being represented by an m-bit character, each character being a 62-bit character code, the method including the steps of: receiving a long chain connection array to be converted, and generating a global unique digital identifier corresponding to each long chain connection based on the long chain connection number in the array; based on the 62-system character codes after the disorder sequence, carrying out 62-system conversion on each digital identifier to obtain a corresponding short chain connection, wherein the short chain connection is represented by n-bit characters, and n is m +4, and the front edge of the characters which are less than n is filled with default characters; and analyzing the first m-bit characters of the short link, determining a data table with the first m-bit characters as a table name, and storing the key value pair into the data table with the short link code as a key and the corresponding long link as a value.
Optionally, in the short link generation method according to the present invention, the 62-ary character code includes 26 lower case letters, 26 upper case letters and 10 digits, which are scrambled by a shuffling algorithm to obtain a 62-digit array, where the 62 characters of the array correspond to digits 0-61, respectively.
Optionally, in the short link generation method according to the present invention, a global information table is stored in the database, the global unique digital identifier is generated by a global identifier, and a timer thread is created in the global identifier for periodically storing the generated self-increment identification number in the global information table.
Optionally, in the short link generation method according to the present invention, each data entry in the data table includes the short link, the corresponding long link, and one or more of an expiration time and a creation time of the short link.
Optionally, in the short link generation method according to the present invention, the method further includes the steps of: and creating a local primary cache and a redis secondary cache, and storing data items corresponding to the short link which are recently requested to be accessed by the user into the local primary cache and the redis secondary cache.
Optionally, in the short link generating method according to the present invention, the step of storing the data entry where the short link recently requested to be accessed by the user is located in the local primary cache and the redis secondary cache includes: receiving a short link access request of a user, wherein the access request comprises a short link of the request; inquiring a long link corresponding to the short link in a local first-level cache by taking the short link as a key; if yes, redirecting the long chain connection; otherwise, the long link corresponding to the short link is inquired in the redis second-level cache.
Optionally, in the short link generation method according to the present invention, the method further includes the steps of: if the long link corresponding to the short link is inquired in the redis second-level cache, the long link is redirected, and the data item where the short link is located is stored in the local first-level cache; if the long link corresponding to the short link is not inquired in the redis secondary cache, analyzing the first m bits of the short link, determining the name of the corresponding data table, inquiring the long link corresponding to the short link from the corresponding data table for reorientation, and storing the data item where the short link is located in the local primary cache and the redis secondary cache.
Optionally, in the short link generation method according to the present invention, m is 2, n is 6, the memory of the local primary cache is 256MB, and the default character is the first character in the 62-bit array.
Optionally, in the short link generating method according to the present invention, when the number generated by the global issuer reaches 62nWhen m is equal to m +1, n is equal to n + 1.
Optionally, in the short link generating method according to the present invention, the step of receiving a long link group to be converted includes: and creating an interface for generating short links in batches, and receiving the long link array through the interface, wherein the input parameters of the interface are the long link array and the corresponding short link expiration time.
Optionally, in the short link generation method according to the present invention, the method further includes the steps of: the short link data entries that have expired are periodically purged.
Optionally, in the short link generating method according to the present invention, the data table name includes a prefix and a suffix, the prefix is a hint word of the short link table, and the suffix is an m-bit character.
According to another aspect of the present invention, there is provided a short link generation apparatus adapted to reside in a server, the server being connected to a database, the database generating a plurality of data tables, each data table name being represented by an m-bit character, each character being a 62-bit character code, the apparatus comprising: the long-chain connection receiving module is suitable for receiving a long-chain connection array to be converted and generating a global unique digital identifier corresponding to each long-chain connection based on the number of the long-chain connections in the array; the short link generation module is suitable for carrying out 62-system conversion on each digital identifier based on the 62-system character codes after the order is disordered to obtain a corresponding short link, wherein the short link is represented by n-bit characters, and n is m +4, and the front edge of the characters which are less than n is filled with default characters; and the short link storage module is suitable for analyzing the first m-bit characters of the short link, determining a data table with the first m-bit characters as a table name, and storing the key value pair into the data table with the short link code as a key and the corresponding long link as a value.
According to still another aspect of the present invention, there is provided a server including: one or more processors; a memory; and one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs, when executed by the processors, implement the steps of the short link generation method as described above.
According to a further aspect of the invention, there is provided a readable storage medium storing one or more programs, the one or more programs comprising instructions, which when executed by a server, implement the steps of the short link generation method as described above.
According to the technical scheme of the invention, the unrepeated short links can be generated in batches, the long links can be efficiently extracted according to the short links, and the user can be quickly responded. In the short link generation process, a global number sender is manufactured, before short links are generated each time, the number of short links is generated according to needs, unique number sections are taken from the global number sender, and the short links are guaranteed to be globally unique. The first m bits (such as the first two bits) of the short link are database table name identifiers, and the short link is stored in a database sub-table persistent mode.
In addition, the invention establishes a local first-level cache for each short link, places the short link recently requested by the user in the local first-level cache, and queries the redis second-level cache if the local cache cannot query the data, and queries the database when the redis second-level cache is not queried. The redis secondary cache associates the generated short link with the long link to accelerate the query speed, and the short link is used as a unique index in the database to accelerate the query speed. Moreover, the invention also supports a short link expiration mechanism, when the user calls to generate the short link interface, the expiration parameters can be transmitted, the expiration time of the short link can be stored in the database, and if the user does not transmit the expiration time, the user can be defaulted to be inexhaustible.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
To the accomplishment of the foregoing and related ends, certain illustrative aspects are described herein in connection with the following description and the annexed drawings, which are indicative of various ways in which the principles disclosed herein may be practiced, and all aspects and equivalents thereof are intended to be within the scope of the claimed subject matter. The above and other objects, features and advantages of the present disclosure will become more apparent from the following detailed description read in conjunction with the accompanying drawings. Throughout this disclosure, like reference numerals generally refer to like parts or elements.
FIG. 1 shows a block diagram of a short link generation system 100 according to one embodiment of the invention;
FIG. 2 shows a block diagram of a server 200 according to one embodiment of the invention;
FIG. 3 shows a flow diagram of a short link generation method 300 according to one embodiment of the invention; and
FIG. 4 shows a block diagram of a short link generation apparatus 400 according to one embodiment of the invention;
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
FIG. 1 shows a schematic diagram of a short link generation system 100 according to one embodiment of the invention. The short link generation system 100 shown in fig. 1 includes a plurality of clients 110, as well as a server 120 and a database 130. It should be noted that the system 100 of fig. 1 is merely exemplary, and in particular implementations there may be a different number of clients 110, as well as servers 120 and databases 130 in the system 100, and the present invention is not limited to the number of devices included in the system, which may also reside in multiple geographic locations.
In general, the client 110 may send a short link access request to the server 120, and the server 120 queries the database for a long link corresponding to the short link to redirect to the long link. The client 110 may be a device such as a mobile phone, a tablet computer, a notebook computer, a television box, a wearable device, etc. which can access the internet. The server 120, such as a file server, a data storage server, an application server, a WEB server, and the like, may also be implemented as a personal computer including a desktop computer and a notebook computer configuration, and may also be implemented as a part of a small-sized portable (or mobile) electronic device. The database 130 may reside in the server 120 as a local database, or may be disposed outside the server 120 as a remote database, and the present invention does not limit the deployment manner of the database 130.
In addition, a plurality of data tables are generated in the database 130, and a plurality of data entries may be stored in the data tables, each of which may include one or more of a short link, a corresponding long link, and an expiration time and a creation time of the short link. Wherein, the short link is the shortened link, the long link is the original link of the short link, and the expiration time means that the short link is invalid when reaching the time and can not be used any more. When the general user calls to generate the short link interface, the expiration parameter can be transmitted, and the expiration time of the short link can be stored in the database. If the user does not pass the expiration time, the default is never expired, and the expiration time item is left empty. The creation time is the time that the short link was generated.
Each data table name is represented by m-bit characters, and each bit character is a 62-system character code. The 62-ary character code comprises 26 lower case letters of 'a-Z', 26 upper case letters of 'A-Z' and 10 numbers of '0-9', and the 62 characters are formed. Furthermore, the 62-ary character codes may be shuffled based on a shuffling algorithm to obtain a 62-bit array. The shuffling algorithm can randomly scramble the 62-bit code, and the invention does not limit the character sequence of the 62-bit array obtained after scrambling. The 62 characters in the 62-bit array correspond to the numbers 0-61 in the decimal system, respectively.
Thus, the name of the data table in the database may be a combination of any two characters in the array, and may be generally sorted by the characters in the array, and named sequentially from front to back. Each data table can be generated in advance or only when needed, and generally, when the data of the previous data table reaches the upper limit, a new data table can be generated again and the name of the new data table is named.
According to one embodiment, the data table name includes a prefix that is a hint word of the short link table and a suffix that is an m-bit character. The prefix may be, for example, shorten _ url, and the full data table name is shorten _ url _ m-bit characters. When m is 2, there may be a data table name shorten _ url _ va, shorten _ url _1s, or the like. Therefore, detailed information of short links and long links can be stored in the database and the table, and the database query can be accelerated by setting the short links as unique indexes.
According to another embodiment, the server 120 may further create a local primary cache 140 and a redis secondary cache 150, which are used for storing short link entries that have been recently queried, so that when a user queries again, the user can directly query a corresponding long link from the local primary cache 140 or the redis secondary cache 150, and thus, the user does not need to query in a database, and request response efficiency is improved. The local primary cache 140 is cached in the memory of the server, so that the access speed is much faster than that of the redis secondary cache, and the access speed can be increased. However, the amount of storage in the redis secondary cache 150 is small, and more recent short link data entries may be stored.
Fig. 2 shows a block diagram of a server 200 according to an embodiment of the invention. In a basic configuration 202, a server 200 typically includes a system memory 206 and one or more processors 204. A memory bus 208 may be used for communication between the processor 204 and the system memory 206.
Depending on the desired configuration, the processor 204 may be any type of processing, including but not limited to: a microprocessor (μ P), a microcontroller (μ C), a Digital Signal Processor (DSP), or any combination thereof. The processor 204 may include one or more levels of cache, such as a level one cache 210 and a level two cache 212, a processor core 214, and registers 216. Example processor cores 214 may include Arithmetic Logic Units (ALUs), Floating Point Units (FPUs), digital signal processing cores (DSP cores), or any combination thereof. The example memory controller 218 may be used with the processor 204, or in some implementations the memory controller 218 may be an internal part of the processor 204.
Depending on the desired configuration, system memory 206 may be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.), or any combination thereof. System memory 206 may include an operating system 220, one or more applications 222, and program data 224. In some implementations, the application 222 can be arranged to operate with program data 224 on an operating system. The program data 224 comprises instructions, and in the server 200 according to the invention the program data 224 contains instructions for performing the short link generation method 300.
The server 200 may also include an interface bus 240 that facilitates communication from various interface devices (e.g., output devices 242, peripheral interfaces 244, and communication devices 246) to the basic configuration 202 via the bus/interface controller 230. The example output device 242 includes a graphics processing unit 248 and an audio processing unit 250. They may be configured to facilitate communication with various external devices, such as a display or speakers, via one or more a/V ports 252. Example peripheral interfaces 244 can include a serial interface controller 254 and a parallel interface controller 256, which can be configured to facilitate communications with external devices such as input devices (e.g., keyboard, mouse, pen, voice input device, touch input device) or other peripherals (e.g., printer, scanner, etc.) via one or more I/O ports 258. An example communication device 246 may include a network controller 260, which may be arranged to facilitate communications with one or more other servers 262 over a network communication link via one or more communication ports 264.
A network communication link may be one example of a communication medium. Communication media may typically be embodied by computer readable instructions, data structures, program modules, and may include any information delivery media, such as carrier waves or other transport mechanisms, in a modulated data signal. A "modulated data signal" may be a signal that has one or more of its data set or its changes made in such a manner as to encode information in the signal. By way of non-limiting example, communication media may include wired media such as a wired network or private-wired network, and various wireless media such as acoustic, Radio Frequency (RF), microwave, Infrared (IR), or other wireless media. The term computer readable media as used herein may include both storage media and communication media.
Server 200 may be implemented as a server, such as a file server, a database server, an application server, a WEB server, etc., or as part of a small-sized portable (or mobile) electronic device, such as a cellular telephone, a Personal Digital Assistant (PDA), a wireless WEB-watch device, an application specific device, or a hybrid device that may include any of the above functions. Server 200 may also be implemented as a personal computer including both desktop and notebook computer configurations. In some embodiments, the server 200 is configured to perform the short link generation method 300.
Fig. 3 shows a flow diagram of a short link generation method 300 according to an embodiment of the invention. Method 300 is performed in a server, such as server 200, to convert long links to short links storage.
As shown in fig. 3, the method begins at step S310. In step S310, a long chain link group to be converted is received, and a globally unique digital identifier corresponding to each long chain link is generated based on the long chain link number in the group.
According to one embodiment, the step of receiving a long chain array to be converted comprises: and creating an interface for generating the short links in batches, and receiving the long link array through the interface, wherein the input parameters of the interface are the long link array and the corresponding short link expiration time. The long chain interface group comprises a plurality of hyperlinks to be converted, such as [ https:// www.autohome.com.cn, https:// club.
According to another embodiment, a global issuer may be invoked to generate a globally unique digital identifier corresponding to each long chain link. The global issuer, which may also be referred to as an ID generator or a unified issuer, can generate a globally unique identification for each object (e.g., long link). The person skilled in the art can create a global issuer himself according to the prior art, without the invention being limited thereto. When the short link interfaces are generated in batches, the global number sender is requested first, the number of the long links in the batch is transmitted, and the number of the last global number sender is obtained, so that all unique number of the long links in the batch can be determined. The global issuer logic is as follows: and calling an INCRBY command of redis, transmitting the number of the batch of long links, and obtaining a result after the actual INCRBY is obtained, wherein the result value is the last digital number of the batch of long links.
For example, the last number of the last long link is 100, and the new long links are 100, the global issuer generates 100 number from 101, that is, 101 and 200, and allocates to the 100 long links respectively. The number acquired by the number sender is one block, so that the number sender is called once without generating one short chain every time, and the short chains can be produced in batch once after one batch calling. Here, the number may not be acquired according to the number of the long links, at this time, the number sender may be called in advance for a single time to take a unique section number segment, then when a batch long link request is received, the section number is sequentially allocated to the long links, if the number is still vacant and not allocated, the number is continuously allocated after the next batch of long links are connected; if the number is not enough, the sender is called again to generate a new number for distribution.
In order to ensure the integrity and the persistence of the cache data of the global numbering device, a global information table (global _ info table) can be stored in a database, a timer thread is created in the global numbering device, and the thread can store the generated self-increment identification number into the global information table at regular time, so that the data loss when the machine is restarted is avoided. This incremented numerical value in the global issuer redis is stored in the global information table of the database, for example, every 1 min. When the program is started, the global sender firstly scans whether the counter has a value in the redis, and if the counter does not have the value, the value of the counter is inquired from the global information table of the number database to be stored in the redis.
The corresponding short chain-linked character can be calculated through the global unique number identification generated by the global number generator, and the algorithm is as follows: the number identifier pair 62 is divided, and the obtained remainder continues to be divided by the number identifier pair 62 until the remainder cannot be divided, namely, the decimal to 62-ary system conversion algorithm is obtained. Each corresponding quotient and final remainder is the final result, and if the number of characters obtained is less than 6, the default characters are used for completion. The default character is the first character in a 62-bit array. Assuming that the first few characters of the 62-bit array are vPh, the n-bit character may be automatically filled in with character v.
Taking a six-bit short link as an example, if the number obtained after calling a global signal generator (a self-increment sequence) is 600, dividing 600 by 62, and taking the quotient 9 remainder as 58; the quotient 58 is divided by 62, with a quotient 0 remainder of 58. According to the 62-bit character array of the invention, the character corresponding to 600 can be found to be LD, if it is less than 6 bits, vvvvv is filled in front, and six-bit short links corresponding to 600 are found to be vvvvLD.
In step S310, a globally unique number corresponding to each long chain link is generated.
Subsequently, in step S320, based on the scrambled 62-ary character codes, 62-ary conversion is performed on each numeric identifier to obtain a corresponding short chain, where the short chain is represented by an n-bit character, and n is m +4, where the front edge of the character with less than n bits is filled with a default character.
In general, m may be 2 and n may be 6, that is, the data table name is expressed as two-bit characters; the short link is represented as a six-digit character or is automatically populated with a default character at the front. Thus, the data of each data table can only be stored 62 at most414,77,336 short web addresses, and the less data in the data table, the faster the access speed, and the way is very suitable for use in the free database such as mysql.
According to one embodiment, when the number generated by the global issuer reaches 62nWhen m is equal to m +1, n is equal to n + 1. For example, initially m is 2, n is 6, but when the global issuer number reaches 626When 56,800,235,584, the number of short chain connection characters and data tables needs to be expanded, as long as the last 4 bits of the short chain connection are ensured to be the real short chain connection identification, and the first few bits are ensured to be the database table name identification. At this point each data table is still stored 624The data table name is changed to three-digit character representation according to the data amount, and the total number of the data table name can be 623A data table.
In step S320, a short chain-linked code corresponding to each long chain link is generated.
Subsequently, in step S330, the first m-bit characters of the short link are parsed, a data table with the first m-bit characters as table names is determined, and the short link code as a key and the corresponding long link as a value are stored in the data table.
And according to the first m-bit character corresponding to the short chain link corresponding to each long chain link, the stored data table identifier is obtained. Taking m as an example, 2, if the first two digits are denoted by vv, the name of the database table to be stored is: short _ url _ vv, with short link as key and corresponding long link as value, is batched into the database table along with the expiration time.
According to an embodiment of the invention, the method 300 may further comprise the steps of: and creating a local primary cache and a redis secondary cache, and storing data items corresponding to the short link which are recently requested to be accessed by the user into the local primary cache and the redis secondary cache. Wherein the first level cache is, for example, ehcache of java, which is created when the web server is started. The secondary cache, namely a redis cache server, is started by a redis-server program. When the short link interfaces are generated in batches by calling each time, after data are inserted into the database, the data can be flushed into the ehcache and the redis in batches through the thread pool by adopting the independent threads, so that the access frequency of the database is reduced, the data response speed is increased, and the pressure of the database is reduced.
Specifically, the data entries corresponding to the short links that the user has recently requested to access may be cached and stored according to the following method: and receiving a short link access request of a user, wherein the access request comprises the requested short link. And then, by taking the short link as a key, inquiring whether a corresponding long link exists in the local first-level cache. If the long link corresponding to the short link is inquired in the local first-level cache, the long link is directly redirected, so that the data response speed is accelerated.
And when the corresponding long link is not inquired in the local first-level cache, the corresponding long link is inquired in the redis second-level cache to judge whether the long link corresponding to the short link exists. If the corresponding hyperlink is inquired, the long link is redirected, and the data item (short link, long link, expiration time, creation time and the like) where the short link is located is stored in the local primary cache. If the short link is not inquired, analyzing the first m-bit characters of the short link, positioning the name of a data table where the short link is located, inquiring the long link corresponding to the short link from the corresponding data table for reorientation, and storing the data item where the short link is located in a local first-level cache and a redis second-level cache for direct reorientation to the long link when the short link is inquired and used next time.
Here, since the short links are scattered in each database table, the database table in which the short link is located can be calculated according to the first two characters of the short link, and the corresponding long-chain ground address can be found from the table. In addition, in each database table, the short links are unique indexes, and the query speed is very high. It should be noted that the query in the present invention means that the queried short link number entry is not expired (the short link expiration time is greater than or equal to the current time), and if the query indicates that the short link in the entry is expired, the user is prompted that the short link is expired, which represents that the short link is invalid. In addition, the method 300 may also renew the short link to be expired by modifying the expiration time in the database, and the modified content may be synchronized into the corresponding two levels of cache.
Preferably, the memory of the local primary cache is set to be 256MB, and the memory of the redis secondary cache is larger than the memory of the primary cache. When the cache reaches the memory limit, short link data entries that are early in the join time or that have expired are automatically purged. Based on the method, the expired short links in the database, the local primary cache and the redis secondary cache can be cleared regularly.
In summary, the present invention can form unique and non-repetitive short links through the number sender, and if the number of short links generated by the whole system exceeds the upper limit, the present invention can also support more short links quickly by expanding short link characters. The global information table stores the unique self-increment digital identification of the global number sender, and the number of the number sender is never lost and has high access speed. The scheme supports the expiration processing and the renewal processing of the short link, and ensures the availability and the completeness of the system. The short links are stored in a database and a table, the data table can be horizontally expanded, and the number of the infinite short links can be supported theoretically. Through the two-level cache strategy, if data cannot be searched in the cache, the data can be quickly located through the database index, the mass data can be quickly searched, the data can never be lost, and the user can be guaranteed to access the data at any time and any place.
Fig. 4 shows a block diagram of a short link generation apparatus 400 according to an embodiment of the present invention, which apparatus 400 may reside in the server 200. The server is connected with a database in a communication way, a plurality of data tables are generated in the database, the name of each data table is represented by an m-bit character, and each bit character is a 62-system character code. Each data entry in the data table includes a short link, a corresponding long link, and one or more of an expiration time and a creation time of the short link. As shown in fig. 4, the apparatus 400 includes: a long link receiving module 410, a short link generating module 420 and a short link storing module 430.
The long link receiving module 410 receives a long link array to be converted, and generates a globally unique digital identifier corresponding to each long link based on the number of long links in the array. The global unique digital identifier is generated through a global number sender, a global information table is stored in a database, and a timer thread is established in the global number sender and used for storing the generated self-increment identification number into the global information table at regular time.
According to one embodiment, the long link receiving module 410 may create an interface for batch generation of short links, and receive the long link set through the interface, where the incoming parameters of the interface are the long link set and the corresponding short link expiration time. The long link receiving module 410 may perform processing corresponding to the processing described above in step S310, and details thereof are not further described here.
The short link generating module 420 performs 62-ary conversion on each digital identifier based on the ordered 62-ary character codes to obtain a corresponding short link, where the short link is represented by an n-bit character, and n is m +4, where the front edge of the character less than n is filled with a default character.
The 62-system character codes comprise 26 lower case letters, 26 upper case letters and 10 numbers, the 62-digit array is obtained after the sequence is disturbed by a shuffling algorithm, and the 62 characters of the array correspond to the numbers 0-61 respectively. The default character is the first character in a 62-bit array. Preferably, m is 2 and n is 6. When the number generated by the global issuer reaches 62nWhen m is equal to m +1, n is equal to n + 1. The short link generation module 420 may perform processing corresponding to the processing described above in step S320, and the detailed description thereof is not repeated here.
The short link storage module 430 parses the first m-bit characters of the short link, determines the data table with the first m-bit characters as the table name, and stores the key value pair into the data table with the short link code as the key and the corresponding long link as the value. According to one embodiment, short link storage module 430 may also periodically purge expired short link data entries. The short link storage module 430 may perform processing corresponding to the processing described above in step S330, and a detailed description thereof will not be repeated.
According to an embodiment of the present invention, the apparatus 400 may further include a cache module (not shown in the figure), adapted to create a local primary cache (the memory may be 256MB) and a redis secondary cache, and store the data entry corresponding to the short link recently requested to be accessed by the user into the local primary cache and the redis secondary cache. Specifically, the cache module may receive a short link access request of a user, where the access request includes a short link of the request; inquiring a long link corresponding to the short link in a local first-level cache by taking the short link as a key; if yes, redirecting the long chain connection; otherwise, the long link corresponding to the short link is inquired in the redis second-level cache.
If the long link corresponding to the short link is inquired in the redis second-level cache, the cache module redirects the long link and stores the data item where the short link is located in the local first-level cache. If the long chain link corresponding to the short chain link is not inquired in the redis secondary cache, the cache module analyzes the first m bits of the short chain link, determines the corresponding data table name, inquires the long chain link corresponding to the short chain link from the corresponding data table for redirection, and stores the data item where the short chain link is located in the local primary cache and the redis secondary cache.
According to the technical scheme of the invention, unrepeated short links can be generated in batch, and the method is suitable for searching mass data. The global number sender generates the unique number of each long link in batch, the number sender is automatically increased by 1 after generating a batch of numbers, and the number sender is stored in a cache and is refreshed into a database at regular time so as to prevent the restart of a machine and the loss of the cache. The short link and long link information are stored in different libraries and tables, the first two characters of each short link are the mark of each table, and each table can store 624A short link. The index value of the data table can be obtained according to the first two characters of the short linkThe corresponding data table is located. The method is suitable for storage and persistent storage of mass data. When short link accesses, the query is preferentially carried out from the two levels of caches, and if the query cannot be obtained from the two levels of caches, the database is queried, so that the access speed can be increased, and the database is liberated. The invention has good user experience, high system availability and complete functions.
A8, the method as in a6, wherein m is 2, n is 6, the memory of the local level one cache is 256MB, and the default character is the first character in the 62-bit array. A9, the method according to any of A1-A7, wherein when the number generated by the global issuer reaches 62nWhen m is equal to m +1, n is equal to n + 1. A10, the method as in any one of a1-a9, wherein the step of receiving a long chain-connection set to be converted comprises: and creating an interface for generating short links in batches, and receiving the long link array through the interface, wherein the input parameters of the interface are the long link array and the corresponding short link expiration time. A11, the method of A5, further comprising the steps of: the short link data entries that have expired are periodically purged.
Thus, the methods and apparatus of the present invention, or certain aspects or portions thereof, may take the form of program code (i.e., instructions) embodied in tangible media, such as removable hard drives, U.S. disks, floppy disks, CD-ROMs, or any other machine-readable storage medium, wherein, when the program is loaded into and executed by a machine, such as a computer, the machine becomes an apparatus for practicing the invention.
In the case of program code execution on programmable computers, the computing device will generally include a processor, a storage medium readable by the processor (including volatile and non-volatile memory and/or storage elements), at least one input device, and at least one output device. Wherein the memory is configured to store program code; the processor is configured to execute the short link generation method of the present invention in accordance with instructions in the program code stored in the memory.
By way of example, and not limitation, readable media may comprise readable storage media and communication media. Readable storage media store information such as computer readable instructions, data structures, program modules or other data. Communication media typically embodies computer readable instructions, data structures, program modules or other data in a modulated data signal such as a carrier wave or other transport mechanism and includes any information delivery media. Combinations of any of the above are also included within the scope of readable media.
In the description provided herein, algorithms and displays are not inherently related to any particular computer, virtual system, or other apparatus. Various general purpose systems may also be used with examples of this invention. The required structure for constructing such a system will be apparent from the description above. Moreover, the present invention is not directed to any particular programming language. It is appreciated that a variety of programming languages may be used to implement the teachings of the present invention as described herein, and any descriptions of specific languages are provided above to disclose the best mode of the invention.
In the description provided herein, numerous specific details are set forth. It is understood, however, that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure an understanding of this description.
Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, various features of the invention are sometimes grouped together in a single embodiment, figure, or description thereof for the purpose of streamlining the disclosure and aiding in the understanding of one or more of the various inventive aspects. However, the disclosed method should not be interpreted as reflecting an intention that: that the invention as claimed requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into this detailed description, with each claim standing on its own as a separate embodiment of this invention.
Those skilled in the art will appreciate that the modules or units or components of the devices in the examples disclosed herein may be arranged in a device as described in this embodiment or alternatively may be located in one or more devices different from the devices in this example. The modules in the foregoing examples may be combined into one module or may be further divided into multiple sub-modules.
Those skilled in the art will appreciate that the modules in the device in an embodiment may be adaptively changed and disposed in one or more devices different from the embodiment. The modules or units or components of the embodiments may be combined into one module or unit or component, and furthermore they may be divided into a plurality of sub-modules or sub-units or sub-components. All of the features disclosed in this specification (including any accompanying claims, abstract and drawings), and all of the processes or elements of any method or apparatus so disclosed, may be combined in any combination, except combinations where at least some of such features and/or processes or elements are mutually exclusive. Each feature disclosed in this specification (including any accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.
Furthermore, those skilled in the art will appreciate that while some embodiments described herein include some features included in other embodiments, rather than other features, combinations of features of different embodiments are meant to be within the scope of the invention and form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.
Furthermore, some of the described embodiments are described herein as a method or combination of method elements that can be performed by a processor of a computer system or by other means of performing the described functions. A processor having the necessary instructions for carrying out the method or method elements thus forms a means for carrying out the method or method elements. Further, the elements of the apparatus embodiments described herein are examples of the following apparatus: the apparatus is used to implement the functions performed by the elements for the purpose of carrying out the invention.
As used herein, unless otherwise specified the use of the ordinal adjectives "first", "second", "third", etc., to describe a common object, merely indicate that different instances of like objects are being referred to, and are not intended to imply that the objects so described must be in a given sequence, either temporally, spatially, in ranking, or in any other manner.
While the invention has been described with respect to a limited number of embodiments, those skilled in the art, having benefit of this description, will appreciate that other embodiments can be devised which do not depart from the scope of the invention as described herein. Furthermore, it should be noted that the language used in the specification has been principally selected for readability and instructional purposes, and may not have been selected to delineate or circumscribe the inventive subject matter. Accordingly, many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the appended claims. The present invention has been disclosed in an illustrative rather than a restrictive sense with respect to the scope of the invention, as defined in the appended claims.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201911215940.1A CN111026985A (en) | 2019-12-02 | 2019-12-02 | Method, device and server for generating short link |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201911215940.1A CN111026985A (en) | 2019-12-02 | 2019-12-02 | Method, device and server for generating short link |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN111026985A true CN111026985A (en) | 2020-04-17 |
Family
ID=70207787
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201911215940.1A Pending CN111026985A (en) | 2019-12-02 | 2019-12-02 | Method, device and server for generating short link |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN111026985A (en) |
Cited By (11)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111651695A (en) * | 2020-05-29 | 2020-09-11 | 深圳前海微众银行股份有限公司 | Method and device for generating and parsing short links |
| CN112861032A (en) * | 2021-01-20 | 2021-05-28 | 银盛通信有限公司 | Short link generation method and system |
| CN113378083A (en) * | 2021-05-19 | 2021-09-10 | 北京沃东天骏信息技术有限公司 | Short link generation method, device, equipment and storage medium |
| CN113761406A (en) * | 2021-09-03 | 2021-12-07 | 深圳市丰巢网络技术有限公司 | Intelligent cabinet two-dimensional code short-chain generation method, device, medium and electronic equipment |
| CN114020462A (en) * | 2021-11-05 | 2022-02-08 | 北京青云科技股份有限公司 | Global identifier generation method, device, equipment and storage medium |
| CN114692027A (en) * | 2020-12-29 | 2022-07-01 | 福建天泉教育科技有限公司 | Method and terminal for reducing short link into long link |
| CN115587609A (en) * | 2022-09-27 | 2023-01-10 | 深圳市智码通科技有限公司 | Short-link two-dimensional code generation method and device |
| CN116226560A (en) * | 2023-03-31 | 2023-06-06 | 深圳市星卡科技股份有限公司 | Short-link generation method and device |
| CN116796099A (en) * | 2022-03-16 | 2023-09-22 | 深圳市腾讯信息技术有限公司 | Short link generation method, device, electronic device and storage medium |
| CN117332166A (en) * | 2023-08-24 | 2024-01-02 | 中国电信股份有限公司 | A link generation method, device, electronic device and storage medium |
| US12554790B2 (en) | 2024-03-29 | 2026-02-17 | The Bank Of New York Mellon | Client computing device resource address shortening |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20120047577A1 (en) * | 2010-08-23 | 2012-02-23 | Microsoft Corporation | Safe url shortening |
| CN106210161A (en) * | 2016-06-24 | 2016-12-07 | 中国银联股份有限公司 | A kind of short chain delivers a child into method and system |
| CN106817375A (en) * | 2017-02-07 | 2017-06-09 | 上海斐讯数据通信技术有限公司 | Link dazzle system and method |
| CN106886568A (en) * | 2017-01-12 | 2017-06-23 | 掌阅科技股份有限公司 | One kind point table method, device and electronic equipment |
| CN106933854A (en) * | 2015-12-30 | 2017-07-07 | 阿里巴巴集团控股有限公司 | Short linking processing method, device and server |
| CN107729409A (en) * | 2017-09-26 | 2018-02-23 | 中国银联股份有限公司 | Method and device for generating short links |
| CN109669960A (en) * | 2018-12-25 | 2019-04-23 | 钛马信息网络技术有限公司 | The system and method for caching snowslide is avoided by multi-level buffer in micro services |
-
2019
- 2019-12-02 CN CN201911215940.1A patent/CN111026985A/en active Pending
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20120047577A1 (en) * | 2010-08-23 | 2012-02-23 | Microsoft Corporation | Safe url shortening |
| CN106933854A (en) * | 2015-12-30 | 2017-07-07 | 阿里巴巴集团控股有限公司 | Short linking processing method, device and server |
| CN106210161A (en) * | 2016-06-24 | 2016-12-07 | 中国银联股份有限公司 | A kind of short chain delivers a child into method and system |
| CN106886568A (en) * | 2017-01-12 | 2017-06-23 | 掌阅科技股份有限公司 | One kind point table method, device and electronic equipment |
| CN106817375A (en) * | 2017-02-07 | 2017-06-09 | 上海斐讯数据通信技术有限公司 | Link dazzle system and method |
| CN107729409A (en) * | 2017-09-26 | 2018-02-23 | 中国银联股份有限公司 | Method and device for generating short links |
| CN109669960A (en) * | 2018-12-25 | 2019-04-23 | 钛马信息网络技术有限公司 | The system and method for caching snowslide is avoided by multi-level buffer in micro services |
Cited By (15)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN111651695A (en) * | 2020-05-29 | 2020-09-11 | 深圳前海微众银行股份有限公司 | Method and device for generating and parsing short links |
| CN114692027B (en) * | 2020-12-29 | 2024-09-20 | 福建天泉教育科技有限公司 | Method and terminal for restoring short link to long link |
| CN114692027A (en) * | 2020-12-29 | 2022-07-01 | 福建天泉教育科技有限公司 | Method and terminal for reducing short link into long link |
| CN112861032A (en) * | 2021-01-20 | 2021-05-28 | 银盛通信有限公司 | Short link generation method and system |
| CN113378083B (en) * | 2021-05-19 | 2023-09-29 | 北京沃东天骏信息技术有限公司 | A short link generation method, device, equipment and storage medium |
| CN113378083A (en) * | 2021-05-19 | 2021-09-10 | 北京沃东天骏信息技术有限公司 | Short link generation method, device, equipment and storage medium |
| WO2022242678A1 (en) * | 2021-05-19 | 2022-11-24 | 北京沃东天骏信息技术有限公司 | Short link generation method and apparatus, device, and storage medium |
| CN113761406A (en) * | 2021-09-03 | 2021-12-07 | 深圳市丰巢网络技术有限公司 | Intelligent cabinet two-dimensional code short-chain generation method, device, medium and electronic equipment |
| CN113761406B (en) * | 2021-09-03 | 2024-06-04 | 丰巢网络技术有限公司 | Intelligent cabinet two-dimension code short-chain generation method and device, medium and electronic equipment |
| CN114020462A (en) * | 2021-11-05 | 2022-02-08 | 北京青云科技股份有限公司 | Global identifier generation method, device, equipment and storage medium |
| CN116796099A (en) * | 2022-03-16 | 2023-09-22 | 深圳市腾讯信息技术有限公司 | Short link generation method, device, electronic device and storage medium |
| CN115587609A (en) * | 2022-09-27 | 2023-01-10 | 深圳市智码通科技有限公司 | Short-link two-dimensional code generation method and device |
| CN116226560A (en) * | 2023-03-31 | 2023-06-06 | 深圳市星卡科技股份有限公司 | Short-link generation method and device |
| CN117332166A (en) * | 2023-08-24 | 2024-01-02 | 中国电信股份有限公司 | A link generation method, device, electronic device and storage medium |
| US12554790B2 (en) | 2024-03-29 | 2026-02-17 | The Bank Of New York Mellon | Client computing device resource address shortening |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN111026985A (en) | Method, device and server for generating short link | |
| CN102810089B (en) | Short link system and implementation method based on content | |
| US8260799B2 (en) | Method and apparatus for creating pattern matching state machine and identifying pattern | |
| JP5420087B2 (en) | Method and system for providing a message including a universal resource locator | |
| US20130141259A1 (en) | Method and system for data compression | |
| WO2020034186A1 (en) | Method for generating short web address, and terminal | |
| CN106210161A (en) | A kind of short chain delivers a child into method and system | |
| CN107729409A (en) | Method and device for generating short links | |
| CN111553670A (en) | Transaction processing method and device and computer readable storage medium | |
| CN112784183A (en) | Short chain joint generation method and device | |
| CN111723113A (en) | Distributed caching method, device, terminal device and storage medium for business data | |
| CN115640471A (en) | Short link generation method and device, computer equipment and storage medium | |
| CN118277628B (en) | Data access control method, device, computer equipment and storage medium | |
| CN111651695A (en) | Method and device for generating and parsing short links | |
| KR101587756B1 (en) | Apparatus and method for searching string data using bloom filter pre-searching | |
| Zhong et al. | FPGA-CPU architecture accelerated regular expression matching with fast preprocessing | |
| CN113420238A (en) | Short link generation method, device, electronic device and storage medium | |
| JP6233846B2 (en) | Variable-length nonce generation | |
| CN110716713A (en) | Method for generating project code and computing equipment | |
| CN107736003A (en) | Improved security for domain names | |
| CN102542019A (en) | Identification code storage method and identification code storage system as well as identification code indexing method and identification code indexing system | |
| CN105931054A (en) | Transaction request processing method, gateway device, agent device, and business device | |
| CN1961269A (en) | Method of and device for querying of protected structured data | |
| CN117171461A (en) | Short link generation method, device, electronic device and storage medium | |
| CN115114504A (en) | A data search method and device |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20200417 |
|
| RJ01 | Rejection of invention patent application after publication |