Disclosure of Invention
In view of this, the embodiments of the present invention provide a method, apparatus, system, and storage medium for generating a short website, which can solve the problem that the efficiency of generating a short website cannot be maintained in a high concurrency scenario when a database self-increasing identification algorithm obtains an identification for generating a short website through database access.
In order to achieve the above object, according to an aspect of the embodiment of the present invention, there is provided a method for generating a short web address.
The method for generating the short website comprises the steps of determining the current minimum value and the current maximum value of a pre-stored identification when the short website corresponding to the target long website is not included in a storage record, generating the target short website according to the identification of the current minimum value if the current minimum value is smaller than or equal to the current maximum value, updating the current minimum value, and determining the target short website as the short website of the target long website.
In one embodiment, the determining the target short web site as the short web site of the target long web site includes:
inquiring whether the storage record comprises the target short website or not;
If not, determining the target short website as the short website of the target long website;
If yes, updating the current minimum value, and when the updated current minimum value is smaller than the current maximum value, regenerating a target short website according to the updated current minimum value, and generating the recalculated target short website into a short website of the target long website.
In yet another embodiment, the generating the target short website according to the identification of the current minimum value includes:
generating codes corresponding to a preset system according to the identification of the current minimum value;
and determining the code corresponding to the preset system as a target short website.
In yet another embodiment, if the current minimum value is not less than the maximum value, the method further comprises:
Acquiring a new minimum value of the identification for generating the short website from the database;
determining a new maximum value of the identifier for generating the short website according to the new minimum value and a preset step length;
Judging whether the new minimum value and the new maximum value belong to a preset coding range or not, wherein the preset coding range is determined according to a preset system and a preset length of a short website;
If yes, updating a new minimum value to the current minimum value, and updating the new maximum value to the current maximum value;
And generating a target short website according to the identification of the current minimum value, and determining the target short website as the short website of the target long website.
In yet another embodiment, if the new minimum value and the new maximum value do not belong to a preset encoding range, the method further includes:
sending a reset instruction to a database, and initializing the database according to the reset instruction;
and receiving a new minimum value of the identification which is sent by the database and used for generating the short website.
In yet another embodiment, after the determining the target short web site as the short web site of the target long web site, the method further includes:
storing the mapping relation between the target long website and the target short website in a storage record;
setting a storage period of a mapping relation between the target long website and the target short website;
and deleting the mapping relation between the target long website and the target short website when the storage time length of the mapping relation reaches the storage time length.
In yet another embodiment, the determining the current minimum and the current maximum of the pre-stored identities includes:
Judging whether the number of generated short websites reaches a threshold value or not in a preset time period;
If not, determining the current minimum value and the current maximum value of the prestored mark.
In order to achieve the above object, according to another aspect of the present invention, there is provided an apparatus for generating a short web address.
The device for generating the short website comprises a determining unit, a generating unit and a determining unit, wherein the determining unit is used for determining the current minimum value and the current maximum value of a pre-stored identifier when the short website corresponding to the target long website is not included in a storage record, the pre-stored identifier is used for generating the short website, the generating unit is used for generating the target short website according to the identifier of the current minimum value and updating the current minimum value if the current minimum value is smaller than or equal to the current maximum value, and the determining unit is also used for determining the target short website as the short website of the target long website.
In an embodiment, the determining unit is specifically configured to:
inquiring whether the storage record comprises the target short website or not;
If not, determining the target short website as the short website of the target long website;
If yes, updating the current minimum value, and when the updated current minimum value is smaller than the current maximum value, regenerating a target short website according to the updated current minimum value, and generating the recalculated target short website into a short website of the target long website.
In a further embodiment, the generating unit is specifically configured to:
generating codes corresponding to a preset system according to the identification of the current minimum value;
and determining the code corresponding to the preset system as a target short website.
In yet another embodiment, if the current minimum value is not less than the maximum value, further comprising:
an obtaining unit, configured to obtain a new minimum value of an identifier for generating a short website from a database;
the determining unit is further used for determining a new maximum value of the identifier for generating the short website according to the new minimum value and a preset step length;
The judging unit is used for judging whether the new minimum value and the new maximum value belong to a preset coding range or not, wherein the preset coding range is determined according to a preset system and a preset length of a short website;
The updating unit is used for updating a new minimum value to the current minimum value and updating the new maximum value to the current maximum value if yes;
the generation unit is specifically configured to generate a target short website according to the identifier of the current minimum value;
The determining unit is specifically configured to determine the target short website as a short website of the target long website.
In yet another embodiment, if the new minimum value and the new maximum value do not belong to a preset encoding range, the method further includes:
the sending unit is used for sending a reset instruction to the database, so that the database is initialized according to the reset instruction;
and the receiving unit is also used for receiving the new minimum value of the identification for generating the short website sent by the database.
In yet another embodiment, further comprising:
the storage unit is used for storing the mapping relation between the target long website and the target short website in a storage record;
the setting unit is used for setting the storage period of the mapping relation between the target long website and the target short website;
And the deleting unit is used for deleting the mapping relation between the target long website and the target short website when the storage time length of the mapping relation reaches the storage time length.
In a further embodiment, the determining unit is specifically configured to:
Judging whether the number of generated short websites reaches a threshold value or not in a preset time period;
If not, determining the current minimum value and the current maximum value of the prestored mark.
In order to achieve the above object, according to another aspect of the present invention, there is provided an apparatus for generating a short web address.
To achieve the above object, according to still another aspect of an embodiment of the present invention, there is provided an electronic apparatus.
The electronic equipment comprises one or more processors and a storage device, wherein the storage device is used for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are enabled to achieve the short website generation method provided by the embodiment of the invention.
To achieve the above object, according to still another aspect of an embodiment of the present invention, a computer-readable medium is provided.
A computer readable medium of an embodiment of the present invention stores a computer program thereon, which when executed by a processor implements a method for generating a short web address provided by the embodiment of the present invention.
The embodiment of the invention has the advantages that in the embodiment of the invention, when the short website corresponding to the target long website is not included in the storage record, the current minimum value and the current maximum value of the prestored mark are determined, when the current minimum value is judged to be smaller than the current maximum value, the target short website can be generated according to the mark of the current minimum value, and the target short website is determined to be the short website of the target long website. In the embodiment of the invention, the target short website is generated through the prestored mark, so that the access times to the database can be reduced, the collision probability of the generated mark is reduced, and meanwhile, the short website generation efficiency can be improved, and especially, the short website generation efficiency under a high concurrency scene is improved.
Further effects of the above-described non-conventional alternatives are described below in connection with the embodiments.
Detailed Description
Exemplary embodiments of the present invention will now be described with reference to the accompanying drawings, in which various details of the embodiments of the present invention are included to facilitate understanding, and are to be considered merely exemplary. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
It is noted that embodiments of the invention and features of the embodiments may be combined with each other without conflict.
The method for generating the short website in the embodiment of the invention can be used in a distributed system which comprises a plurality of nodes and a database connected with each node. The database may be a cache database, for example, redis, and each node may acquire an identification segment for generating a short website from the database and store the identification segment in the memory, and each node may sequentially use the identification segment for generating the short website from the current minimum value of the identification according to the identifications stored in the memory, so as to ensure the uniqueness of the short website generation. The database can store an identification position and an identification increment step length, wherein the identification position represents the current generation position of the identification for generating the short website, and the identification increment step length represents the length of each time the node acquires the identification, namely each time the node acquires the value of the identification section from the database, ranging from the identification position to the identification position, and adding the value of the identification increment step length. The database receives the acquisition instruction of the node, can return the identification position to the node as a new current minimum value identified in the node, indicates that the node can use the identification from the value belonging to the identification position to the value of the identification position plus the identification increment step length to generate a short website, and then stores the value of the identification position plus the identification increment step length as the new identification position so as to be convenient for returning to the new identification position after the next node request.
Because of the distributed system, there may be multiple nodes that acquire the identity from the database at the same time, the database may determine the location identity returned to each node by minId = incrby (key, by), where minId represents the new minimum value returned to the node, by represents the identity increment step, and key represents the location identity stored by the database.
In the embodiment of the invention, in order to avoid generating the short website for the same long website, each node may store the corresponding relationship between the generated short website and the corresponding long website, for example, store the corresponding relationship as a storage record in a database. When each node needs to convert a long website into a short website, a storage record can be queried in advance, if the storage record comprises the corresponding relation between the long website and the corresponding short website, the short website corresponding to the long website is indicated to be included in the storage record, the short website corresponding to the long website can be directly obtained from the storage record, and if the storage record does not comprise the short website corresponding to the long website, the short website is required to be generated in the mode of the embodiment of the invention.
Because the number of the marks is limited, the marks can be recycled to generate short websites, and therefore, the storage period for setting the corresponding relation between each long website and the short website in the storage record is set in the embodiment of the invention. For example, the storage period is set to 10 days. When the storage time of the corresponding relation between the long website and the short website reaches the storage period, deleting the corresponding relation between the long website and the short website so that the corresponding identifications of the short websites can be reused for generating the short websites corresponding to other long websites.
Because of the limited number of identifiers used to generate short web addresses, each time the identifiers are exhausted, the identifiers may be reused to generate short web addresses by initializing the locations of the identifiers in the database. However, the corresponding relation between the generated short website and the corresponding long website is stored in the storage record, so that the use time of the identifiers can be set in order to avoid the repeated use of the identifiers, namely, the identifiers which can only use a preset range in a preset time period are set, so that the identifiers are ensured to be circularly used, and the storage period of the generated short website is up before the identifiers are deleted. For example, setting the usable identification range to be 0-N, and the storage period to be 10 days, and the usable identification range per day can be equally allocated, then it is obtained that the usable identification range per day is sequentially greater than 0 and less than or equal to N/10, greater than N/10 and less than or equal to 2N/10, greater than 2N/10 and less than or equal to 3N/10,..once the database is initialized after the 10 th day, the short web address generated by the identification in the range greater than 0 and less than or equal to N/10 is deleted, thereby avoiding the reuse of the identification.
Since the use time of the marks is set, it is possible to determine whether or not the short marks can also be generated according to the number of the use marks within the set preset time period. In the embodiment of the invention, before the short website is generated according to the identifier, whether the number of the generated short websites reaches a threshold value in a set time period can be judged, the threshold value represents the number of the used identifiers in the preset time period, if not, the short website can be generated, and the step S101 is executed, and if not, the embodiment of the invention is not executed to generate the short website.
The embodiment of the invention provides a method for generating a short website, which can be executed by nodes in a distributed system, as shown in fig. 1, and comprises the following steps.
S101, when the storage record does not comprise a short website corresponding to the target long website, determining the current minimum value and the current maximum value of the pre-storage mark.
The pre-stored identifier is used for generating a short website and represents the identifier pre-stored in the node and used for generating the short website.
When the node needs to convert the long website into the short website, the node can firstly query the storage record, and the corresponding relation between the generated short website and the corresponding long website is stored in the storage record. Therefore, if the storage record includes the corresponding relation between the target long website and the corresponding short website, the short website corresponding to the target long website is indicated to be included in the storage record, the short website corresponding to the target long website can be directly obtained from the storage record, and if the storage record does not include the short website corresponding to the target long website, the short website is required to be generated by the mode of the embodiment of the invention.
When the storage record does not include the short website corresponding to the target long website, the short website is required to be generated.
The current minimum and maximum values of the pre-stored identifiers represent the minimum and maximum values of the current identifier range pre-stored in the memory of the node that can be used to generate the short web address. For example, stored identifications are 1050 through 1999, then the current minimum is 1050 and the current maximum is 1999.
S102, if the current minimum value is smaller than the current maximum value, generating a target short website according to the identification of the current minimum value, and updating the current minimum value.
The prestored identifiers in the node memory are sequentially used for generating the short websites from the current minimum value in sequence, and the current minimum value can be increased by a preset value for updating every time after the short websites are generated, so that the updated current minimum value is larger than the current maximum value when the prestored identifiers are used up, and when the short websites are needed to be generated again, whether the current minimum value is larger than the current maximum value or not can be judged after the current minimum value and the current maximum value of the prestored identifiers are determined in the step S101. If the current minimum value is not greater than the current maximum value, indicating that the prestored mark in the memory is not used up, generating the target short website directly according to the mark of the current minimum value. If the current minimum value is greater than the current maximum value, the pre-stored identification in the memory is used up, and at the moment, the identification for generating the short website is required to be retrieved from the database for storage.
In the embodiment of the invention, the mode of generating the target short website according to the identifier of the current minimum value can be concretely that a code corresponding to a preset system is generated according to the identifier of the current minimum value, and the code corresponding to the preset system is determined as the target short website.
In the embodiment of the invention, the code of the preset system can be used as the short website, so that the identification of the current minimum value can be converted into the code of the preset system to generate the target short website.
For example, the preset number may be 62, and the 62-gram character table is 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRST UVWXYZ (62 characters total). The number of bits of the short web address is set to be 2, so that the identification of the current minimum value can be converted into a 2-bit code of 62 scale in the step to be used as the short web address.
After the target short website is generated according to the identification of the current minimum value, the current minimum value can be updated in such a way that the current minimum value is increased by a preset value so as to judge that the current minimum value is larger than the current maximum value when the short website is generated next time, wherein the preset value can take the value of 1.
In the embodiment of the invention, when the current minimum value is greater than the current maximum value, the identification for generating the short website is required to be re-acquired from the database, and the target short website is generated. The method comprises the steps of obtaining a new minimum value for generating the identification of the short website from a database, determining a new maximum value for generating the identification of the short website according to the new minimum value and a preset step length, judging whether the new minimum value and the new maximum value belong to a preset coding range or not, wherein the preset coding range is determined according to a preset system and a preset length of the short website, if so, updating the new minimum value to be the current minimum value, updating the new maximum value to be the current maximum value, generating a target short website according to the identification of the current minimum value, and determining the target short website to be the short website of the target long website.
When the current minimum value is larger than the current maximum value, the node can send an instruction for acquiring the identification to the database, and then the database returns a new minimum value for generating the identification of the short website, namely the node acquires the new minimum value for generating the identification of the short website from the database. And setting a preset step length which is the same as the value of the increment step length of the database identifier in the node, and then increasing the value of the new minimum value by the preset step length and then subtracting the preset value to determine the new maximum value corresponding to the new minimum value. After the new minimum value and the new maximum value are determined in this way, the identification range for generating the short website, which is obtained from the database, can be determined.
In the embodiment of the invention, the short website is generated by converting the identifier into the preset system, and only the identifier within the preset encoding range can be successfully converted, so that after the new minimum value and the new maximum value are determined, whether the new minimum value and the new maximum value belong to the preset encoding range or not is also required to be judged, wherein the preset encoding range is determined according to the preset system and the preset length of the short website.
If the new minimum value and the new maximum value are judged to belong to the preset coding range, the identification obtained from the database is indicated to be capable of being used for generating the short website, the new minimum value can be updated to be the current minimum value, and the new maximum value can be updated to be the current maximum value. Because the current minimum value and the current maximum value are both the identification ranges newly obtained from the database, the generation of the target short web address according to the identification of the current minimum value, the updating of the current minimum value and the determination of the target short web address as the short web address of the target long web address can be directly performed.
In the above process, if it is determined that the new minimum value and the new maximum value do not belong to the preset encoding range, it is indicated that the identifier generated in the database has exceeded the preset encoding range, and at this time, the database may be initialized, that is, the identified position in the database is initialized to an initial value. It can be executed specifically by sending a reset instruction to the database, initializing the database according to the reset instruction, and receiving a new minimum value of the identifier sent by the database for generating the short web address.
After the node sends a reset instruction to the database, the database may directly return a new minimum value for generating the identification of the short web address after performing initialization.
It should be noted that, when each node is initialized, the current minimum value of the identifier may be set to be greater than the current maximum value, so that the node directly obtains the identifier for generating the short website from the database for storage after initialization.
S103, determining the target short website as the short website of the target long website.
After the short website is generated, the target short website can be determined to be the short website of the target long website in the embodiment of the invention.
In order to avoid the repeated use of the mark, the method can be specifically implemented by inquiring whether the storage record comprises a target short website or not, if not, determining the target short website as a short website of the target long website, if so, updating the current minimum value, and when the updated current minimum value is smaller than the current maximum value, regenerating the target short website according to the updated current minimum value, and generating the recalculated target short website as the short website of the target long website.
After the target short web address is generated in step S102, the stored record may be queried. If the stored record includes the target short website, it is indicated that the target short website is still being used, and in order to avoid repetition, the short website needs to be regenerated again at this time, that is, the current minimum value is updated, and when the updated current minimum value is smaller than the current maximum value, the target short website is regenerated according to the updated current minimum value, and the recalculated target short website is generated as the short website of the target long website. If the stored record does not include the target short website, the target short website is not used, and the target short website can be directly determined to be the short website of the target long website.
After the step is executed, the mapping relation between the target long website and the target short website can be stored in a storage record, and the storage period is set for the storage record. And deleting when the storage time length reaches the storage time length.
In the embodiment of the invention, when the short website corresponding to the target long website is empty in the storage record, the current minimum value and the current maximum value of the prestored mark are determined, and when the current minimum value is smaller than the current maximum value, the target short website can be generated according to the mark of the current minimum value and is determined to be the short website of the target long website. In the embodiment of the invention, the target short website is generated through the prestored mark, so that the access times to the database can be reduced, the collision probability of the generated mark is reduced, and meanwhile, the short website generation efficiency can be improved, and especially, the short website generation efficiency under a high concurrency scene is improved.
In the embodiment of the present invention, the preset step length and the preset value can be set according to the requirements. For example, the preset step size may be set to 1000, and the preset value is set to 1, so that each node accesses the database once every 1000 short websites are generated, and therefore, the performance is 1000 times faster than that of the conventional database algorithm. In the embodiment of the invention, the number of bits of the short website can also be set according to the requirement, for example, the short website is set to be a 5-bit 62-ary code, and the code direction of the short website is 10000-ZZZZZ.
With reference to the embodiment shown in fig. 1, a method for generating a short website in the embodiment of the present invention is specifically described, and as shown in fig. 2, the method includes the following steps.
S201, initializing a current minimum value and a current maximum value of a pre-stored identification.
When the node initially executes the embodiment of the invention, the current minimum value and the current maximum value of the prestored mark can be initialized. When initializing, the node memory is usually not provided with a prestored identifier, and the current minimum value of the identifier is set to be larger than the current maximum value, so that the node can directly acquire the identifier for generating the short website from the database for storage after initializing. For example, the current minimum value is minId, the initialization value is-1, the current maximum value is maxId, and the initialization value is-2, so minId is greater than maxId, the process of retrieving the identification from the database is performed. The initialization in the node may also include a preset step size that is the same as the value of the database identification increment step size.
S202, judging whether the current minimum value is larger than the current maximum value, if so, executing the step S203, and if not, executing the step S206.
The current minimum value is greater than the current maximum value, which indicates that the current storage identifier is exhausted and no usable identifier exists, and the identifier needs to be acquired from the database. The current minimum value is not greater than the current maximum value, which indicates that the current stored identifier is not used up, and that there is an available identifier, step S206 may be directly performed.
S203, acquiring a new minimum value from the database, and determining a new maximum value according to the new minimum value.
When the node needs to acquire the identifier from the database, an acquisition instruction can be sent to the database, the database returns a new minimum value of the usable identifier, and then the new maximum value is determined according to a preset step length. And setting a preset step length which is the same as the value of the increment step length of the database identifier in the node, and then increasing the value of the new minimum value by the preset step length and then subtracting the preset value, thereby determining the new maximum value corresponding to the new minimum value.
For example, if the preset step size is 1000, the new minimum value is 2000, and the preset value is 1, it may be determined that the new maximum value is 2000+1000-1 equal to 2999.
S204, judging whether the new minimum value and the new maximum value are in a preset range, if so, executing the step S205, and if not, executing the step S210.
Only the marks within the preset encoding range can be successfully converted, so that after the new minimum value and the new maximum value are determined, whether the new minimum value and the new maximum value belong to the preset encoding range or not needs to be judged. The preset coding range is determined according to a preset system and a preset length of a short website. For example, the short web address is 2-bit 62-system code, that is, the value of the short web address ranges from 10 to ZZ, the value range corresponding to the 10-system code is 62-3843, so the 10-system mark needs to be in the range of 62-3843 to successfully convert the short web address, so the preset range is 62-3843, that is, the new minimum value needs to be not less than 62, and the new maximum value needs to be not more than 3843.
And S205, updating the new minimum value to the current minimum value and updating the new maximum value to the current maximum value.
If the new minimum value and the new maximum value are judged to belong to the preset coding range, the fact that the identification obtained from the database can be used for generating the short website is indicated, the new minimum value can be updated to be the current minimum value, and the new maximum value can be updated to be the current maximum value, so that the short website can be conveniently generated subsequently.
S206, generating a target short website according to the identification of the current minimum value.
The short website is generated by converting the identification of the current minimum value into a preset code. For example, setting the short web address to be a 2-bit 62-ary code, and the current minimum value is identified as 62, the generated target short identifier is 10.
And S207, increasing the current minimum value by a preset value.
After the short web address is generated using the current preset value, the current minimum value may be incremented by the preset value to represent the identifier used to generate the short web address next time.
S208, judging whether the storage record comprises a target short website, if so, executing the step S202, and if not, executing the step S209.
If the short website and the corresponding long website are already generated in the storage record, after the target short website is generated, whether the storage record includes the target short website can be judged to avoid repetition. If so, the target short web address needs to be regenerated, and the step S202 is executed, and if not, the step S209 can be directly executed.
S209, determining the target short website as a short website corresponding to the target long website, and adding the corresponding relation between the target long website and the target short website in the storage record.
The target short website can be used, and then the target short website can be determined to be the short website corresponding to the target long website.
After the target short website is determined to be the short website corresponding to the target long website, the mapping relationship between the target long website and the target short website can be stored in a storage record, and a storage period is set for the storage record. And deleting when the storage time length reaches the storage time length. And S210, sending a reset instruction to the database, receiving a new minimum value of the identification for generating the short website sent by the database, and determining a new maximum value according to the new minimum value.
And sending a reset instruction to the database so as to initialize the identification in the database.
Because of the scenario involving multi-node concurrent operation, i.e., multiple nodes sending reset instructions to the database at the same time, the distributed lock may be added prior to sending the reset instructions in embodiments of the present invention. That is, multiple nodes call the distributed lock at the same time, but only one node is successfully locked, that is, the database only executes the reset instruction of the successfully locked node. After the node executes the program for calling the distributed lock, if the database returns YES, the reset instruction can be sent to initialize the database and wait for the feedback of the database, the database can directly return to the new minimum value after the initialization, if the data returns NO, the step S205 can be directly executed after waiting for a period of time to acquire the identification from the database. In the embodiment of the present invention, since the present node is successfully locked, a reset instruction is sent to the database, then a new minimum value returned from the database is waited, a new maximum value is determined according to the new minimum value, and then step S205 is executed.
In the embodiment of the invention, when the short website corresponding to the target long website is empty in the storage record, the current minimum value and the current maximum value of the prestored mark are determined, and when the current minimum value is smaller than the current maximum value, the target short website can be generated according to the mark of the current minimum value and is determined to be the short website of the target long website. In the embodiment of the invention, the target short website is generated through the prestored mark, so that the access times to the database can be reduced, the collision probability of the generated mark is reduced, and meanwhile, the short website generation efficiency can be improved, and especially, the short website generation efficiency under a high concurrency scene is improved.
In order to solve the problems in the prior art, an embodiment of the present invention provides a device 300 for generating a short website, as shown in fig. 3, the device 300 includes:
a determining unit 301, configured to determine, when the storage record does not include a short website corresponding to the target long website, a current minimum value and a current maximum value of a pre-storage identifier, where the pre-storage identifier is used to generate the short website;
A generating unit 302, configured to generate a target short website according to the identifier of the current minimum value and update the current minimum value if the current minimum value is less than or equal to the current maximum value;
The determining unit 301 is further configured to determine the target short website as a short website of the target long website.
It should be understood that the manner of implementing the embodiment of the present invention is the same as that of implementing the embodiment shown in fig. 1, and will not be described herein.
In one implementation manner of the embodiment of the present invention, the determining unit 301 is specifically configured to:
inquiring whether the storage record comprises the target short website or not;
If not, determining the target short website as the short website of the target long website;
If yes, updating the current minimum value, and when the updated current minimum value is smaller than the current maximum value, regenerating a target short website according to the updated current minimum value, and generating the recalculated target short website into a short website of the target long website.
In yet another embodiment, the generating unit 302 is specifically configured to:
generating codes corresponding to a preset system according to the identification of the current minimum value;
and determining the code corresponding to the preset system as a target short website.
In yet another embodiment, if the current minimum value is not less than the maximum value, the apparatus 300 further includes:
an obtaining unit, configured to obtain a new minimum value of an identifier for generating a short website from a database;
the determining unit is further used for determining a new maximum value of the identifier for generating the short website according to the new minimum value and a preset step length;
the apparatus 300 further comprises:
The judging unit is used for judging whether the new minimum value and the new maximum value belong to a preset coding range or not, wherein the preset coding range is determined according to a preset system and a preset length of a short website;
The updating unit is used for updating a new minimum value to the current minimum value and updating the new maximum value to the current maximum value if yes;
the generating unit 302 is specifically configured to generate a target short website according to the identifier of the current minimum value;
The determining unit 301 is specifically configured to determine the target short website as a short website of the target long website.
In yet another embodiment, if the new minimum value and the new maximum value do not belong to a preset encoding range, the apparatus 300 further includes:
the sending unit is used for sending a reset instruction to the database, so that the database is initialized according to the reset instruction;
and the receiving unit is also used for receiving the new minimum value of the identification for generating the short website sent by the database.
In yet another embodiment, the apparatus 300 further comprises:
the storage unit is used for storing the mapping relation between the target long website and the target short website in a storage record;
the setting unit is used for setting the storage period of the mapping relation between the target long website and the target short website;
And the deleting unit is used for deleting the mapping relation between the target long website and the target short website when the storage time length of the mapping relation reaches the storage time length.
In yet another embodiment, the determining unit 301 is specifically configured to:
Judging whether the number of generated short websites reaches a threshold value or not in a preset time period;
If not, determining the current minimum value and the current maximum value of the prestored mark.
It should be understood that the manner of implementing the embodiments of the present invention is the same as that of implementing the embodiments shown in fig. 1 or fig. 2, and will not be described herein.
In the embodiment of the invention, when the storage record does not comprise the short website corresponding to the target long website, the current minimum value and the current maximum value of the prestored mark are determined, and when the current minimum value is smaller than the current maximum value, the target short website can be generated according to the mark of the current minimum value, and the target short website is determined to be the short website of the target long website. In the embodiment of the invention, the target short website is generated through the prestored mark, so that the access times to the database can be reduced, the collision probability of the generated mark is reduced, and meanwhile, the short website generation efficiency can be improved, and especially, the short website generation efficiency under a high concurrency scene is improved.
According to an embodiment of the present invention, the present invention also provides an electronic device and a readable storage medium.
The electronic device comprises at least one processor and a memory in communication connection with the at least one processor, wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method for generating the short website provided by the embodiment of the invention.
Fig. 4 illustrates an exemplary system architecture 400 of a short web site generation method or short web site generation apparatus to which embodiments of the present invention may be applied.
As shown in fig. 4, the system architecture 400 may include terminal devices 401, 402, 403, a network 404, and a server 405. The network 404 is used as a medium to provide communication links between the terminal devices 401, 402, 403 and the server 405. The network 404 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
A user may interact with the server 405 via the network 404 using the terminal devices 401, 402, 403 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 401, 402, 403.
The terminal devices 401, 402, 403 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 405 may be a server providing various services, such as a background management server (by way of example only) providing support for shopping-type websites browsed by users using the terminal devices 401, 402, 403. The background management server may analyze and process the received data such as the product information query request, and feed back the processing result (e.g., product information—only an example) to the terminal device.
It should be noted that, the method for generating a short website provided in the embodiment of the present invention is generally executed by the server 405, and accordingly, the device for generating a short website is generally disposed in the server 405.
It should be understood that the number of terminal devices, networks and servers in fig. 4 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Referring now to FIG. 5, there is illustrated a schematic diagram of a computer system 500 suitable for use in implementing embodiments of the present invention. The computer system illustrated in fig. 5 is merely an example, and should not be construed as limiting the functionality and scope of use of embodiments of the present invention.
As shown in fig. 5, the computer system 500 includes a Central Processing Unit (CPU) 501, which can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the system 500 are also stored. The CPU 501, ROM 502, and RAM 503 are connected to each other through a bus 504. An input/output (I/O) interface 505 is also connected to bus 504.
Connected to the I/O interface 505 are an input section 506 including a keyboard, a mouse, and the like, an output section 507 including a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, a speaker, and the like, a storage section 508 including a hard disk, and the like, and a communication section 509 including a network interface card such as a LAN card, a modem, and the like. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
In particular, according to embodiments of the present disclosure, the processes described above with reference to flowcharts may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable medium, the computer program comprising program code for performing the method shown in the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the present invention are performed when the computer program is executed by a Central Processing Unit (CPU) 501.
The computer readable medium shown in the present invention may be a computer readable signal medium or a computer readable storage medium, or any combination of the two. The computer readable storage medium can be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples of a computer-readable storage medium may include, but are not limited to, an electrical connection having one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. In the present invention, however, the computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, with the computer-readable program code embodied therein. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination of the foregoing. A computer readable signal medium may also be any computer readable medium that is not a computer readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a unit, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
The units involved in the embodiments of the present invention may be implemented in software or in hardware. The described units may also be provided in a processor, which may be described, for example, as a processor comprising a receiving unit, a determining unit, an obtaining unit and a comparing unit. The names of these units do not in any way constitute a limitation of the unit itself, for example, a receiving unit may also be described as a "unit of the function of the receiving unit".
As a further aspect, the invention also provides a computer readable medium which may be comprised in the device described in the above embodiments or may be present alone without being fitted into the device. The computer readable medium carries one or more programs which, when executed by a device, cause the device to perform the method of short web site generation provided by the present invention.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives can occur depending upon design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.