Methods, apparatus, electronic devices and storage media for sequence generation

By obtaining the maximum value and update step of the continuous identification in the database, determining the starting value and generating a unique sequence, it solves the problem that UUID generated identification cannot guarantee continuity, meets the needs of continuous sequence scenarios, and improves performance and efficiency.

CN113111626BActive Publication Date: 2024-10-18BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202010032687.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-01-13
Publication Date
2024-10-18
Estimated Expiration
2040-01-13

AI Technical Summary

Technical Problem

The existing method of generating UUID identifiers cannot guarantee the continuity of generated identifiers and cannot meet the needs of scenarios that require continuous sequences.

Method used

By sending a continuous identification acquisition request to the database, receive and use the maximum value of the continuous identification, the identification increment value and the continuous identification update step to determine the starting value of the continuous identification, and generate a unique sequence based on the starting value. If the identification is incremented If the value is greater than the maximum value, a new continuous identifier will be obtained again. If the sum of the identifier and the update step exceeds the threshold, the database will be initialized.

Benefits of technology

It realizes the need to generate continuous sequences without frequent access to the database, and improves performance and efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113111626B_ABST
    Figure CN113111626B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, electronic device and storage medium for sequence generation, and relates to the field of computer technology. A specific implementation of the method includes: sending a request for obtaining a continuous identifier to a database; receiving the maximum value of the continuous identifier sent by the database; determining the starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step; determining the starting value as the current identifier, and generating a unique sequence according to the current identifier, wherein the current identifier represents the identifier in the continuous identifier currently used to generate a unique sequence. This implementation can solve the problem that the method of generating identifiers by UUID cannot guarantee the continuity of the generated sequence and cannot meet the needs of the scene requiring continuous identification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a sequence generation method, device, electronic device and storage medium. Background Art

[0002] In many scenarios, it is necessary to generate a unique sequence to distinguish parameters of the same type. These unique sequences are usually generated based on a unique identifier, so how to generate a unique identifier becomes an important issue. Currently, a unique identifier can be generated by UUID. UUID (Universally Unique Identifier) ​​is a unique identifier generated by combining software, hardware, time and other information. It is a 32-bit string that can make the generated identifier unique.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] The UUID method of generating identifiers cannot guarantee the continuity of the generated identifiers and cannot meet the needs of scenarios that require a continuous sequence. Summary of the invention

[0005] In view of this, the embodiments of the present invention provide a method, device, system and storage medium for sequence generation, which can solve the problem that the UUID generation identification method cannot guarantee the continuity of the generated sequence and cannot meet the needs of scenarios requiring continuous identification.

[0006] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for generating a sequence is provided.

[0007] A sequence generation method according to an embodiment of the present invention comprises: sending a request for obtaining a continuous identifier to a database; receiving a maximum value of the continuous identifier sent by the database; determining a starting value of the continuous identifier according to the maximum value of the continuous identifier, an identifier increment value and a continuous identifier update step; determining the starting value as a current identifier, and generating a unique sequence according to the current identifier, wherein the current identifier represents an identifier in the continuous identifier currently used to generate a unique sequence.

[0008] In one embodiment, after generating a unique sequence according to the current identifier, it also includes: judging whether the current identifier is greater than the maximum value after being incremented by the identifier increment value; if so, resending a request to obtain a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determining the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value and the continuous identifier update step, and determining the starting value of the new continuous identifier as the current identifier, and generating a unique sequence according to the current identifier; if not, generating a unique sequence according to the value after the current identifier is incremented by the identifier increment value.

[0009] In another embodiment, before sending the request for obtaining the continuous identifier to the database, it also includes: judging whether the sum of the current identifier and the continuous identifier update step is greater than the identifier threshold; if so, sending an initialization instruction to the database; the sending the request for obtaining the continuous identifier to the database includes: if not, sending the request for obtaining the continuous identifier to the database.

[0010] In yet another embodiment, sending the initialization instruction to the database further includes:

[0011] Determine whether the value of the loop parameter is no loop; if not, send an initialization instruction to the database.

[0012] To achieve the above objective, according to one aspect of an embodiment of the present invention, a method for generating a sequence is provided.

[0013] A sequence generation method according to an embodiment of the present invention includes: receiving a request for obtaining a continuous identifier sent by a client; determining a maximum value of the continuous identifier according to a current value of the identifier and a preset identifier update step; and sending the maximum value of the continuous identifier to the client.

[0014] In one embodiment, receiving an initialization instruction sent by a client;

[0015] Determine whether the sum of the current value of the identifier and the preset identifier update step is greater than the identifier threshold; if so, update the current value of the identifier to the initial value, and determine the maximum value of the new continuous identifier based on the current value of the updated identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client; if not, determine the maximum value of the new continuous identifier based on the current value of the identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client.

[0016] To achieve the above objective, according to another aspect of the present invention, a device for generating a sequence is provided.

[0017] A sequence generation device of the present invention comprises: a sending unit, used for sending a request for obtaining a continuous identifier to a database; a receiving unit, used for receiving the maximum value of the continuous identifier sent by the database; a determining unit, used for determining the starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step; and a generating unit, used for determining the starting value as the current identifier and generating a unique sequence according to the current identifier, wherein the current identifier represents the identifier in the continuous identifier currently used to generate the unique sequence.

[0018] In one embodiment, it further includes:

[0019] A judging unit, used to judge whether the current identifier after being incremented by the identifier increment value is greater than the maximum value;

[0020] The generating unit is further configured to: if yes, resend a request for obtaining a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determine the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value and the continuous identifier update step, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence according to the current identifier;

[0021] The generating unit is further configured to: if not, generate a unique sequence according to a value obtained by incrementing the current identifier by the identifier increment value.

[0022] In yet another embodiment, further comprising:

[0023] A judging unit, used to judge whether the sum of the current identifier and the continuous identifier update step is greater than an identifier threshold;

[0024] The sending unit is further configured to send an initialization instruction to the database if yes; and send a request for obtaining a continuous identifier to the database if no.

[0025] In yet another embodiment, the sending unit is further configured to:

[0026] Determine whether the value of the loop parameter is no loop; if not, send an initialization instruction to the database.

[0027] To achieve the above objective, according to another aspect of the present invention, a device for generating a sequence is provided.

[0028] A sequence generation device of the present invention includes: a receiving unit, used to receive a request for obtaining a continuous identifier sent by a client; a determining unit, used to determine the maximum value of the continuous identifier according to the current value of the identifier and a preset identifier update step; and a sending unit, used to send the maximum value of the continuous identifier to the client.

[0029] In one embodiment, the receiving unit is further used to receive an initialization instruction sent by the client;

[0030] Also includes:

[0031] A judging unit, used to judge whether the sum of the current value of the flag and the preset flag update step is greater than a flag threshold;

[0032] The determining unit is further configured to update the current value of the identifier to the initial value if yes, determine the maximum value of the new continuous identifier according to the current value of the updated identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client;

[0033] The determining unit is further configured to, if not, determine the maximum value of the new continuous identifier according to the current value of the identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client.

[0034] To achieve the above objective, according to another aspect of an embodiment of the present invention, an electronic device is provided.

[0035] An electronic device according to an embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the sequence generation method provided by the embodiment of the present invention.

[0036] To achieve the above objective, according to another aspect of an embodiment of the present invention, a computer readable medium is provided.

[0037] A computer-readable medium according to an embodiment of the present invention stores a computer program, and when the program is executed by a processor, the method for generating a sequence according to an embodiment of the present invention is implemented.

[0038] An embodiment of the above invention has the following advantages or beneficial effects: In the embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database. After the database returns the maximum value of the continuous identifier of the client, the starting value of the continuous identifier can be determined according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step. After the starting value is determined as the current identifier, a unique sequence is generated according to the current identifier. In this way, in the embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0039] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0041] Figure 1 is a schematic diagram of a main process of a method for sequence generation according to an embodiment of the present invention;

[0042] Figure 2 is a schematic diagram of another main process of a method for generating a sequence according to an embodiment of the present invention;

[0043] Figure 3 is a schematic diagram of another main process of a method for generating a sequence according to an embodiment of the present invention;

[0044] Figure 4 is a schematic diagram of main units of a sequence generation apparatus according to an embodiment of the present invention;

[0045] Figure 5 is a schematic diagram of main units of a sequence generation apparatus according to an embodiment of the present invention;

[0046] Figure 6 is another exemplary system architecture diagram to which the embodiments of the present invention can be applied;

[0047] Figure 7 It is a schematic diagram of the structure of a computer system suitable for implementing the embodiment of the present invention. DETAILED DESCRIPTION

[0048] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0049] It should be pointed out that the embodiments of the present invention and the features in the embodiments may be combined with each other if there is no conflict.

[0050] The method for sequence generation in the embodiment of the present invention can be used in a distributed system, and the distributed system includes multiple clients and a database connected to each client. The database can be specifically a cache database, such as redis. Each client can obtain a continuous identifier for generating a unique sequence from the database and store it. The client uses it in sequence according to the identifier order to generate a unique sequence. The current identifier can be used in the client to indicate the position of the used identifier in the continuous identifier. When the unique sequence needs to be generated next time, the current identifier can be incremented by the value after the identifier increment value to generate a unique sequence. The identifier increment value can specifically be 1. The current value of the identifier and the preset identifier update step can be stored in the database. The current value of the identifier indicates the current generation position of the identifier. The preset identifier update step indicates the number of continuous identifiers requested by the client, and also indicates the length of the continuous identifier generated by the database for the client. After the database receives the client's request for the identifier, the current value of the identifier can be used as the starting value of the continuous identifier, and the value after increasing the current value of the identifier by a preset identifier update step is used as the maximum value of the continuous identifier. The database can send this maximum value to the client so that the client can determine the specific value of the continuous identifier based on the maximum value, and at the same time update this maximum value to the current value of the identifier, so that the maximum value of the continuous identifier can be generated for the client next time using this maximum value as the starting value.

[0051] The embodiment of the present invention provides a method for sequence generation, which can be executed by a client in a distributed system, such as Figure 1 As shown, the method includes the following steps.

[0052] S101: Sending a request for obtaining a continuous identifier to a database.

[0053] When the client needs to generate a unique sequence, it can access the database to obtain an identifier for generating the unique sequence. In the embodiment of the present invention, the client can obtain a continuous identifier from the database, so the client can send a request for a continuous identifier to the database.

[0054] In one implementation of an embodiment of the present invention, according to business requirements or storage limitations, the identifier usually has a value range, and the maximum value of the identifier value range is determined as the identifier threshold. When the identifier is used to the identifier threshold, the database can be initialized so that the database can cyclically use the identifier. Therefore, before sending a request to obtain continuous identifiers to the database, in order to avoid the obtained continuous identifiers exceeding the identifier threshold, the client can first determine whether the obtained continuous identifiers will exceed the identifier threshold. If the identifier threshold is exceeded, the database needs to be initialized. Specifically, it can be executed as follows: determine whether the sum of the current identifier and the continuous identifier update step is greater than the identifier threshold; if so, send an initialization instruction to the database; if not, send a request to obtain continuous identifiers to the database.

[0055] The current identifier in the client is the identifier currently in use. The minimum value that can be taken when obtaining the maximum value of the new continuous identifier from the database is the sum of the current identifier and the continuous identifier update step. Therefore, in the embodiment of the present invention, it can be determined whether the sum of the current identifier and the continuous identifier update step is greater than the identifier threshold. If the sum of the current identifier and the continuous identifier update step is greater than the identifier threshold, it can be determined that the maximum value of the new continuous identifier obtained must exceed the identifier threshold, and it is necessary to send an initialization instruction to the database to initialize the identifier in the database. If the sum of the current identifier and the continuous identifier update step is less than the identifier threshold, it can be determined that the maximum value of the new continuous identifier obtained does not necessarily exceed the identifier threshold, and a request to obtain the continuous identifier can be sent to the database, that is, this step is executed.

[0056] If necessary, the client can also set a loop parameter to indicate whether the identifier can be used in a loop. If the loop parameter is set to non-loop, it means that the identifier cannot be used in a loop. At this time, the client can directly prompt that there is no available identifier to indicate that a unique sequence cannot be generated. If the loop parameter is set to loop, it means that the identifier can be used in a loop. At this time, the client can send an initialization instruction to the database. Therefore, in the above process, the way in which the client sends the initialization instruction to the database also includes: judging whether the value of the loop parameter is non-loop; if not, sending an initialization instruction to the database.

[0057] S102: Receive the maximum value of the continuous identifier sent by the database.

[0058] After the client sends a request for a continuous identifier, the database can return the maximum value of the continuous identifier to the client. The maximum value of the continuous identifier indicates the maximum value of the continuous identifier generated by the database for the client to use to generate a unique sequence.

[0059] S103: Determine the starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step.

[0060] The identifier increment value indicates the difference between adjacent identifiers. The next identifier can be obtained by incrementing the previous identifier by the identifier increment value. The continuous identifier update step indicates the length of each continuous identifier obtained from the database. Its value is the same as the preset identifier update step set in the database.

[0061] In the embodiment of the present invention, after receiving the maximum value of the continuous identifier sent by the database, the starting value of the continuous identifier can be determined based on the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step length. The specific method is: the maximum value of the continuous identifier is subtracted from the continuous identifier update step length and then the identifier increment value is added to obtain the starting value of the continuous identifier.

[0062] For example, the continuous flag update step is set to 50 and the flag increment value is set to 1. If the maximum value of the continuous flag received in step S102 is 50, it can be determined that the starting value of the continuous flag is 50-50+1=1.

[0063] After the starting value of the continuous identifier is determined, it means that the client can start from the starting value of the continuous identifier and use the identifiers in the continuous identifier in sequence to generate a unique sequence.

[0064] S104: Determine the starting value as the current identifier, and generate a unique sequence according to the current identifier.

[0065] The current identifier indicates the identifier currently used to generate a unique sequence in the continuous identifier. The client can use the identifiers in the continuous identifier in ascending order to generate a unique sequence. After obtaining the continuous identifier, the starting value of the continuous identifier is the first identifier in the continuous identifier used to generate a unique sequence, so the starting value can be determined as the current identifier, and then the client generates a unique sequence based on the current identifier.

[0066] It should be noted that the embodiment of the present invention does not limit the manner in which the client generates a unique sequence.

[0067] In another implementation of the embodiment of the present invention, after executing step S104, the client will request to generate a unique sequence again, and the execution process may be: determine whether the current identifier is greater than the maximum value after the identifier increment value is incremented; if so, resend the continuous identifier acquisition request to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determine the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value and the continuous identifier update step, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence according to the current identifier; if not, generate a unique sequence according to the current identifier, and increment the current identifier by the identifier increment value.

[0068] After executing step S104, the current identifier has been used to generate a unique sequence, so the current identifier needs to be updated, that is, the current identifier is incremented by the identifier increment value, so that the current representation is updated to the next identifier to be used, so as to facilitate the subsequent generation of a unique sequence. After the current identifier is incremented by the identifier increment value, in order to prevent the identifier used to generate a unique sequence from exceeding the range of continuous identifiers, it is also necessary to determine whether the current identifier after incrementing the identifier increment value is greater than the maximum value of the continuous identifiers.

[0069] If the current identifier is incremented and the value is greater than the maximum value of the continuous identifier, it means that the continuous identifier has been used up. At this time, it is necessary to resend a request to obtain the continuous identifier to the database so that the database can regenerate a new continuous identifier for the client and return the maximum value of the new continuous identifier. After the client receives the maximum value of the new continuous identifier, it can determine the starting value of the new continuous identifier based on the maximum value of the new continuous identifier, the identifier increment value and the continuous identifier update step, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence based on the current identifier.

[0070] If the value of the current identifier after the increment is not greater than the maximum value of the continuous identifier, it means that the continuous identifier has not been exhausted. At this time, a unique sequence can be directly generated based on the value of the current identifier after the increment, and the value of the current identifier after the increment is updated as the current identifier.

[0071] Through the above process of the implementation mode of the present invention, the process of the client using the continuous identifier to generate a unique sequence can be realized.

[0072] In the embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database, and then determine the starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step, and after determining the starting value as the current identifier, generate a unique sequence according to the current identifier. In this way, in the embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0073] The embodiment of the present invention provides another method for sequence generation, which can be executed by a server that sets a database in a distributed system, such as Figure 2 As shown, the method includes the following steps.

[0074] S201: Receive a request for obtaining a continuous identifier sent by a client.

[0075] When the client needs a continuous identifier, it can send a request to obtain the continuous identifier to the database. After receiving the request to obtain the continuous identifier sent by the client, the database needs to generate a continuous identifier for the client.

[0076] S202: Determine the maximum value of the continuous identifiers according to the current value of the identifier and the preset identifier update step size.

[0077] The database stores the current value and the preset identifier update step. The current value is used as the starting position of the continuous identifier, and then the preset identifier update step is added to the current value to determine the maximum value of the continuous identifier. If the database is redis, the HINCRBY command of the hash table (HINCRBY seqKey field preset identifier update step) can be used. This command can set the current value of the identifier to increase the preset identifier update step and return the maximum value of the continuous identifier.

[0078] Taking redis as an example, the identifier is stored in redis by the K->V structure of redis, which only stores the current value of the identifier. Since the architecture of redis is multi-master and high availability can be achieved, the access of the identifier in this solution is stable and highly available.

[0079] S203: Send the maximum value of the continuous identifier to the client.

[0080] After determining the maximum value of the continuous identifier requested by the client, the maximum value of the continuous identifier may be sent to the client, so that the client can determine the range of the continuous identifier.

[0081] In one implementation of an embodiment of the present invention, according to business requirements or storage limitations, the identifier usually has a value range, and the maximum value of the identifier value range is determined as the identifier threshold. When the identifier is used to the identifier threshold, the database can be initialized so that the database can cyclically use the identifier. The process of database initialization can be performed as follows: receiving an initialization instruction sent by the client; determining whether the sum of the current value of the identifier and the preset identifier update step is greater than the identifier threshold; if so, updating the current value of the identifier to the initial value, and determining the maximum value of the new continuous identifier based on the current value of the updated identifier and the preset identifier update step, and sending the maximum value of the new continuous identifier to the client; if not, determining the maximum value of the new continuous identifier based on the current value of the identifier and the preset identifier update step, and sending the maximum value of the new continuous identifier to the client.

[0082] Since multiple clients may send initialization instructions to the database at the same time, in order to avoid repeated initialization, after the database receives the initialization instruction sent by the client, it can determine whether the sum of the current value of the identifier and the preset identifier update step is greater than the identifier threshold. If the database has completed initialization, the sum of the current value of the identifier and the preset identifier update step will not be greater than the identifier threshold, then there is no need to initialize again at this time, and the maximum value of the new continuous identifier can be directly determined based on the current value of the identifier and the preset identifier update step, and the maximum value of the new continuous identifier is sent to the client. If the database is not initialized, the sum of the current value of the identifier and the preset identifier update step will be greater than the identifier threshold, then it is necessary to first update the current value of the identifier to the initial value, that is, initialize, and then determine the maximum value of the new continuous identifier based on the current value of the updated identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client. The above process can avoid repeated initialization of the database.

[0083] In the embodiment of the present invention, the database can execute the above process by using LUA script. The specific code can be as follows.

[0084]

[0085]

[0086] In the above code, KEYS[1] represents the current value of the identifier, ARGV[1] represents the preset identifier update step, ARGV[2] represents the identifier threshold, and ARGV[3] represents the initial value of the identifier.

[0087] The embodiment of the present invention implements the above process through a LUA script, which can ensure the atomicity of multiple operations, that is, ensure the atomicity of the initialization instruction, and avoid the concurrency problem caused by the distributed locking method.

[0088] In an embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database. After the database returns the maximum value of the continuous identifier of the client, the starting value of the continuous identifier can be determined according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step. After the starting value is determined as the current identifier, a unique sequence is generated according to the current identifier. In this way, in an embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0089] Combination Figure 1 and Figure 2 The embodiment shown in the figure, the embodiment of the present invention provides another method for sequence generation, which can be executed by any client and database in the distributed system, such as Figure 3 As shown, the method includes the following steps.

[0090] S301, the client sends a request for obtaining a continuous identifier to the database.

[0091] In the initial state, the client can initialize the preset identifier update step length, and the value of the preset identifier update step length is the same as the value of the preset identifier update step length in the database, and then send a continuous identifier acquisition request to the database to obtain the continuous identifier used to generate a unique sequence.

[0092] S302: The database determines the maximum value of the continuous identifiers according to the current value of the identifier and the preset identifier update step, and updates the maximum value of the continuous identifiers to the current value of the identifier.

[0093] After receiving the client request, the database can determine the maximum value of the continuous identification according to the current value of the identification and the preset identification update step. At the same time, the database also needs to update the current value of the identification, that is, update the maximum value of the continuous identification to the current value of the identification.

[0094] S303: The database sends the maximum value of the continuous identifier to the client.

[0095] After the database determines the maximum value of the consecutive identifiers, it can be sent to the client.

[0096] S304: The client determines a starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value, and the continuous identifier update step.

[0097] The execution of this step is the same as step S103 and will not be repeated here.

[0098] S305: The client determines the starting value as the current identifier, and generates a unique sequence according to the current identifier.

[0099] After the client generates a unique sequence according to the current identifier, if it receives a request for generating a unique sequence, it can execute subsequent steps.

[0100] S306: The client determines whether the current identifier is greater than the maximum value after the identifier is incremented.

[0101] After the current identifier is incremented by the identifier increment value, it becomes the next identifier used to generate a unique sequence.

[0102] S307: If not, generate a unique sequence according to the value after the current identifier is incremented by the identifier increment value, and update the current identifier by the identifier increment value as the current identifier.

[0103] After the client executes this step, if it receives a request for generating a unique sequence, it may execute step S306.

[0104] S308: If yes, a request for obtaining a new continuous identifier is sent to the database.

[0105] S309: The database determines the maximum value of new continuous identifiers according to the current value of the identifier and the preset identifier update step, and updates the maximum value of the new continuous identifier to the current value of the identifier.

[0106] S310: The database sends the maximum value of the new continuous identifier to the client.

[0107] S311, the client determines the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value and the continuous identifier update step.

[0108] S312: The client determines the starting value of the new continuous identifier as the current identifier, and generates a unique sequence according to the current identifier.

[0109] After the client executes this step, if it receives a request for generating a unique sequence, it may execute step S306.

[0110] It should be noted that in the embodiment of the present invention, the database can be a cache database, specifically redis. Based on redis, it is possible to obtain fast, efficient, continuous and non-repetitive identification under high concurrency conditions, and support the setting of identification thresholds, thereby realizing the circular use of identification.

[0111] In an embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database. After the database returns the maximum value of the continuous identifier of the client, the starting value of the continuous identifier can be determined according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step. After the starting value is determined as the current identifier, a unique sequence is generated according to the current identifier. In this way, in an embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0112] In order to solve the problems existing in the prior art, the embodiment of the present invention provides a sequence generation device 400, such as Figure 4 As shown, the device 400 includes:

[0113] The sending unit 401 is used to send a request for obtaining a continuous identifier to a database;

[0114] A receiving unit 402, configured to receive a maximum value of a continuous identifier sent by the database;

[0115] A determination unit 403, configured to determine a starting value of the continuous identifier according to a maximum value of the continuous identifier, an identifier increment value, and a continuous identifier update step size;

[0116] The generating unit 404 is configured to determine the starting value as a current identifier and generate a unique sequence according to the current identifier, wherein the current identifier represents an identifier in the continuous identifiers currently used to generate a unique sequence.

[0117] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 1 The method of the illustrated embodiment is the same and will not be repeated here.

[0118] In an implementation manner of the embodiment of the present invention, the apparatus 400 further includes:

[0119] A judging unit, used to judge whether the current identifier after being incremented by the identifier increment value is greater than the maximum value;

[0120] The generating unit 404 is further configured to: if yes, resend a request for obtaining a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determine the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value, and the continuous identifier update step, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence according to the current identifier;

[0121] The generating unit 404 is further configured to: if not, generate a unique sequence according to a value obtained by incrementing the current identifier by the identifier increment value.

[0122] In another implementation of the embodiment of the present invention, the device further includes:

[0123] A judging unit, used to judge whether the sum of the current identifier and the continuous identifier update step is greater than an identifier threshold;

[0124] The sending unit is further configured to send an initialization instruction to the database if yes; and send a request for obtaining a continuous identifier to the database if no.

[0125] In another implementation of the embodiment of the present invention, the sending unit 401 is further configured to:

[0126] Determine whether the value of the loop parameter is no loop;

[0127] If not, an initialization instruction is sent to the database.

[0128] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 1 or Figure 3 The method of the illustrated embodiment is the same and will not be repeated here.

[0129] In an embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database. After the database returns the maximum value of the continuous identifier of the client, the starting value of the continuous identifier can be determined according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step. After the starting value is determined as the current identifier, a unique sequence is generated according to the current identifier. In this way, in an embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0130] In order to solve the problems existing in the prior art, an embodiment of the present invention provides a sequence generation device 500, such as Figure 5 As shown, the device 500 includes:

[0131] The receiving unit 501 is used to receive a request for obtaining a continuous identifier sent by a client;

[0132] A determination unit 502, configured to determine a maximum value of consecutive identifiers according to a current value of the identifier and a preset identifier update step size;

[0133] The sending unit 503 is configured to send the maximum value of the continuous identifier to the client.

[0134] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 2 The method of the illustrated embodiment is the same and will not be repeated here.

[0135] In an implementation of the embodiment of the present invention, the receiving unit 501 is further configured to receive an initialization instruction sent by the client;

[0136] The device 500 further includes:

[0137] A judging unit, used to judge whether the sum of the current value of the flag and the preset flag update step is greater than a flag threshold;

[0138] The determining unit 502 is further configured to update the current value of the identifier to the initial value, determine the maximum value of the new continuous identifier according to the current value of the updated identifier and the preset identifier update step, and send the maximum value of the new continuous identifier to the client;

[0139] The determining unit 502 is further configured to, if not, determine a maximum value of a new continuous identifier according to a current value of the identifier and a preset identifier update step, and send the maximum value of the new continuous identifier to the client.

[0140] It should be understood that the manner of implementing the embodiments of the present invention is different from the Figure 2 or Figure 3The method of the illustrated embodiment is the same and will not be repeated here.

[0141] In an embodiment of the present invention, the client can send a request to obtain a continuous identifier to the database. After the database returns the maximum value of the continuous identifier of the client, the starting value of the continuous identifier can be determined according to the maximum value of the continuous identifier, the identifier increment value and the continuous identifier update step. After the starting value is determined as the current identifier, a unique sequence is generated according to the current identifier. In this way, in an embodiment of the present invention, the client obtains the continuous identifier from the database, and can generate a unique sequence according to the continuous identifier, meeting the needs of the continuous sequence generation scenario, and at the same time, there is no need to frequently access the database to obtain the continuous identifier, thereby improving performance and efficiency.

[0142] According to an embodiment of the present invention, the present invention also provides an electronic device and a readable storage medium.

[0143] The electronic device of the present invention comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the one processor, and the instructions are executed by the at least one processor so that the at least one processor executes the sequence generation method provided in an embodiment of the present invention.

[0144] Figure 6 An exemplary system architecture 600 is shown to which the method or apparatus for sequence generation according to the embodiments of the present invention may be applied.

[0145] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0146] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0147] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0148] The server 605 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as product information - only an example) to the terminal device.

[0149] It should be noted that the sequence generation method provided in the embodiment of the present invention is generally executed by the server 605 , and accordingly, the sequence generation device is generally disposed in the server 605 .

[0150] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0151] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 suitable for implementing an embodiment of the present invention. Figure 7 The computer system shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0152] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0153] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.

[0154] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0155] It should be noted that 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 above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, 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 disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0156] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a unit, a program segment, or a part of a code, and the above-mentioned unit, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0157] The units involved in the embodiments of the present invention may be implemented by software or hardware. The units described may also be set in a processor, for example, it may be described as: a processor includes a sending unit, a receiving unit, a determining unit, and a generating unit. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the sending unit may also be described as a "unit of the function of the sending unit".

[0158] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device executes the sequence generation method provided by the present invention.

[0159] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for sequence generation, characterized in that: include: Send a request to the database for continuous identification; receiving a maximum value of consecutive identifiers sent by the database; Determining a starting value of the continuous identifier according to the maximum value of the continuous identifier, the identifier increment value, and the continuous identifier update step; Determine the starting value as the current identifier, and generate a unique sequence according to the current identifier, where the current identifier represents the identifier currently used to generate the unique sequence among the continuous identifiers; After generating a unique sequence according to the current identifier, the method further includes: Determine whether the current identifier after being incremented by the identifier increment value is greater than the maximum value; If so, resending a request to obtain a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determining the starting value of the new continuous identifier according to the maximum value of the new continuous identifier, the identifier increment value, and the continuous identifier update step size, and determining the starting value of the new continuous identifier as the current identifier, and generating a unique sequence based on the current identifier; If not, a unique sequence is generated according to the value obtained by incrementing the current identifier by the identifier increment value.

2. The method according to claim 1, characterized in that Before sending the acquisition request of the continuous identifier to the database, the method further includes: Determine whether the sum of the current identifier and the continuous identifier update step is greater than an identifier threshold; If so, sending an initialization instruction to the database; The sending of the acquisition request of the continuous identification to the database includes: If not, a request for obtaining a continuous identifier is sent to the database.

3. The method according to claim 2, characterized in that The sending of the initialization instruction to the database further includes: Determine whether the value of the loop parameter is non-loop; If not, an initialization instruction is sent to the database.

4. A method for sequence generation, characterized in that: include: Receive a request for obtaining a continuous identifier sent by the client; Determine the maximum value of consecutive identifiers based on the current value of the identifier and the preset identifier update step size; Sending the maximum value of the continuous identifier to the client, so that the client determines the starting value of the continuous identifier based on the maximum value of the continuous identifier, the identifier increment value, and the continuous identifier update step; determining the starting value as the current identifier, and generating a unique sequence based on the current identifier; Determine whether the current identifier, after being incremented by the identifier increment value, is greater than the maximum value; if so, resend a request to obtain a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determine the starting value of the new continuous identifier based on the maximum value of the new continuous identifier, the identifier increment value, and the continuous identifier update step size, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence based on the current identifier; If not, a unique sequence is generated according to a value obtained by incrementing the current identifier by the identifier increment value, wherein the current identifier represents an identifier currently used to generate a unique sequence in the continuous identifiers.

5. The method according to claim 4, characterized in that Also includes: Receive initialization instructions sent by the client; Determine whether the sum of the current value of the identifier and the preset identifier update step is greater than an identifier threshold; If so, updating the current value of the identifier to the initial value, determining a maximum value of a new continuous identifier based on the current value of the updated identifier and a preset identifier update step, and sending the maximum value of the new continuous identifier to the client; If not, determining a maximum value of a new continuous identifier according to the current value of the identifier and a preset identifier update step, and sending the maximum value of the new continuous identifier to the client.

6. A sequence generation device, characterized in that: include: A sending unit, configured to send a request for obtaining a continuous identifier to a database; A receiving unit, configured to receive a maximum value of consecutive identifiers sent by the database; a determining unit, configured to determine a starting value of the continuous identifier according to a maximum value of the continuous identifier, an identifier increment value, and a continuous identifier update step; A generating unit is configured to determine the starting value as a current identifier and generate a unique sequence according to the current identifier, wherein the current identifier represents an identifier currently used to generate the unique sequence among the continuous identifiers: Also includes: A judging unit, configured to judge whether the current identifier after being incremented by the identifier increment value is greater than the maximum value; The generating unit is further configured to: if so, resend a request to obtain a new continuous identifier to the database; after receiving the maximum value of the new continuous identifier sent by the database, determine a starting value of the new continuous identifier based on the maximum value of the new continuous identifier, the identifier increment value, and the continuous identifier update step size; determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence based on the current identifier; The generating unit is further configured to: if not, generate a unique sequence according to a value obtained by incrementing the current identifier by the identifier increment value.

7. A sequence generation device, characterized in that: include: A receiving unit, configured to receive a request for obtaining a continuous identifier sent by a client; a determination unit, configured to determine a maximum value of consecutive identifiers based on a current value of the identifier and a preset identifier update step size; a sending unit, configured to send the maximum value of the continuous identifier to the client, so that the client determines a starting value of the continuous identifier based on the maximum value of the continuous identifier, the identifier increment value, and the continuous identifier update step; determines the starting value as the current identifier, and generates a unique sequence based on the current identifier; Determine whether the current identifier, after being incremented by the identifier increment value, is greater than the maximum value; if so, resend a request to obtain a new continuous identifier to the database, and after receiving the maximum value of the new continuous identifier sent by the database, determine the starting value of the new continuous identifier based on the maximum value of the new continuous identifier, the identifier increment value, and the continuous identifier update step size, and determine the starting value of the new continuous identifier as the current identifier, and generate a unique sequence based on the current identifier; If not, a unique sequence is generated according to a value obtained by incrementing the current identifier by the identifier increment value, wherein the current identifier represents an identifier currently used to generate a unique sequence in the continuous identifiers.

8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

9. A computer-readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.

Citation Information

Patent Citations

  • Sequence generating method and device

    CN106570097A

  • Identifier distribution method and device, server and storage medium

    CN109446202A

  • Identifier generation method and device

    CN110109912A

  • Single use identifier values for network accessible devices

    US9571275B1

  • Method and apparatus for processing request from client

    WO2017076193A1