Method, apparatus, system, and medium for generating identifier

文档序号:1719778 发布日期:2019-12-17 浏览:19次 中文

阅读说明:本技术 生成标识符的方法、装置、系统和介质 (Method, apparatus, system, and medium for generating identifier ) 是由 卞祥 沈志明 金晓明 周龙亭 于 2018-05-22 设计创作,主要内容包括:本公开提供了一种生成标识符的方法、装置、系统和介质。所述生成标识符的方法包括:获取表征第一标识符的生成时间的第一时间信息,获取用于生成所述第一标识符的实例的标识信息,获取所述第一标识符的序列号,基于所述第一时间信息、所述实例的标识信息、以及所述第一标识符的序列号生成所述第一标识符。本公开还可提供了了一种用于生成标识符的方法、装置、系统和介质。所述用于生成标识符的方法包括接收为特定业务生成标识符的请求,响应于所述请求,确定为所述特定业务提供标识符生成服务的一个或多个实例,以及通过所述一个或多个实例中的一个实例根据本公开提供的生成标识符的方法生成标识符。(the present disclosure provides a method, apparatus, system, and medium for generating an identifier. The method for generating the identifier comprises the following steps: the method includes acquiring first time information characterizing a generation time of a first identifier, acquiring identification information of an instance used for generating the first identifier, acquiring a serial number of the first identifier, and generating the first identifier based on the first time information, the identification information of the instance, and the serial number of the first identifier. The present disclosure may also provide a method, apparatus, system, and medium for generating an identifier. The method for generating an identifier includes receiving a request to generate an identifier for a particular service, determining, in response to the request, one or more instances of providing an identifier generation service for the particular service, and generating, by one of the one or more instances, an identifier according to a method of generating an identifier provided by the present disclosure.)

1. A method of generating an identifier, comprising:

Obtaining first time information representing a generation time of a first identifier, wherein the first time information is [0, 2 ]M) An integer within the range;

Obtaining identification information of an instance used for generating the first identifier, wherein the identification information of the instance is [0, 2%N) An integer within the range;

Obtaining a sequence number of the first identifier, wherein the sequence number of the first identifier is [0, 2 ]R) An integer within the range;

Based on the first time information, theidentification information of an instance, and a sequence number of the first identifier, wherein the first identifier is [0, 2 ]M+N+R+x) An integer within the range, wherein M, N and R are each a positive integer of 1 or more, and x is an integer of 0 or more.

2. The method of claim 1, wherein generating the first identifier based on the first time information, the identification information of the instance, and a sequence number of the first identifier comprises:

Generating the first identifier by a bit operation, comprising:

ID=time<<(R+N)|machine_id<<R|seq,

Wherein, ID is the first identifier, time is the first time information, machine _ ID is the identification information of the instance, and seq is the serial number of the first identifier.

3. The method of claim 2, wherein:

A unit of measure of the first time information comprises milliseconds; and/or

M-41, N-10, and R-12.

4. The method of claim 1, wherein:

The method further comprises the following steps:

Receiving request information for generating the first identifier;

The obtaining first time information characterizing a generation time of the first identifier includes:

In response to the received request information, acquiring current time information representing the current time and second time information representing the generation time of a second identifier, wherein the second identifier is an identifier generated by the instance before the current time;

comparing the current time information with the second time information, wherein the current time information and the second time information are integers accumulated by a preset timing unit from the same timing starting point;

Determining the first time information based on a result of the comparison.

5. The method of claim 4, wherein determining the first time information based on the result of the comparison comprises:

In response to the current time information being less than the second time information, determining that an identifier generation service provided by the instance is in error; or

In response to the current time information being greater than the second time information, determining to take the current time information as the first time information; or

In response to the current time information being equal to the second time information, determining the first time information according to whether the instance has resources to continue generating identifiers in a timing unit in which the current time is, including:

determining to use the second time information as the first time information on the condition that the instance has a resource for continuing to generate an identifier; or

Waiting to generate the first identifier in a next timing unit after a current time on a condition that the instance does not have resources to continue generating identifiers; and determining next time information characterizing the next timing unit as the first time information.

6. The method of claim 5, wherein, in response to the current time information being equal to the second time information, determining the first time information based on whether there are resources within a timing unit in which the instance continues to generate identifiers at the current time, further comprises:

Determining whether the instance has resources for continuing to generate the identifier in the timing unit in which the current time is, including:

after the serial number of the second identifier is acquired and added with 1, 2 is addedRCalculating the result of the remainder;

When the calculation result is zero, determining that the instance does not continuously generate the resource of the identifier in the timing unit of the current time; or

And when the calculation result is not zero, determining that the instance has the resource for continuously generating the identifier in the timing unit where the current time is.

7. The method of claim 5, wherein obtaining a sequence number for the first identifier comprises:

When the first time information is different from the second time information, randomly determining any number of 0-9 as a serial number of the first identifier; or

When the first time information is the same as the second time information, adding 1 to the sequence number of the second identifier to obtain the sequence number of the first identifier.

8. A method for generating an identifier, comprising:

Receiving a request to generate an identifier for a particular service;

Determining, in response to the request, one or more instances of a service to generate for the particular service provisioning identifier; and

The first identifier is generated by one of the one or more instances according to the method of any of claims 1 to 7.

9. The method of claim 8, further comprising:

Registering the one or more instances to enable the one or more instances to provide the identifier generation service for the particular transaction.

10. An apparatus that generates an identifier, comprising:

A time information obtaining module, configured to obtain first time information representing a generation time of a first identifier, where the first time information is [0, 2 ]M) An integer within the range;

An instance identification obtaining module, configured to obtain identification information of an instance used for generating the first identifier, where the identification information of the instance is [0, 2N) An integer within the range;

A serial number obtaining module, configured to obtain a serial number of the first identifier, where the serial number of the first identifier is [0, 2 ]R) An integer within the range;

An identifier generation module to generate the first identifier based on the first time information, the identification information of the instance, and a sequence number of the first identifier, wherein the first identifier is [0, 2 ]M+N+R+x) An integer within the range, wherein M, N and R are each a positive integer of 1 or more, and x is an integer of 0 or more.

11. The apparatus of claim 10, wherein the identifier generation module is specifically configured to generate the first identifier by a bit operation, comprising:

ID=time<<(R+N)|machine_id<<R|seq,

Wherein, ID is the first identifier, time is the first time information, machine _ ID is the identification information of the instance, and seq is the serial number of the first identifier.

12. The apparatus of claim 11, wherein:

a unit of measure of the first time information comprises milliseconds; and/or

m-41, N-10, and R-12.

13. The apparatus of claim 10, wherein:

the device further comprises:

a request information receiving module for receiving request information for generating the first identifier;

And

the time information acquisition module includes:

A time information obtaining sub-module, configured to obtain, in response to the received request information, current time information representing a current time and second time information representing a generation time of a second identifier, where the second identifier is an identifier generated by the instance before the current time;

the time information comparison submodule is used for comparing the current time information with the second time information, wherein the current time information and the second time information are integers which are obtained by starting from the same timing starting point and accumulating by a preset timing unit;

a time information determination submodule for determining the first time information based on the comparison result.

14. The apparatus of claim 13, wherein the time information determination submodule is specifically configured to:

in response to the current time information being less than the second time information, determining that an identifier generation service provided by the instance is in error; or

In response to the current time information being greater than the second time information, determining to take the current time information as the first time information; or

In response to the current time information being equal to the second time information, determining the first time information according to whether the instance has resources to continue generating identifiers in a timing unit in which the current time is, including:

determining to use the second time information as the first time information on the condition that the instance has a resource for continuing to generate an identifier; or

Waiting to generate the first identifier in a next timing unit after a current time on a condition that the instance does not have resources to continue generating identifiers; and determining next time information characterizing the next timing unit as the first time information.

15. The apparatus of claim 14, wherein, in response to the current time information being equal to the second time information, determining the first time information based on whether there are resources within a timing unit in which the instance continues to generate identifiers at the current time, further comprises:

determining whether the instance has resources for continuing to generate the identifier in the timing unit in which the current time is, including:

After the serial number of the second identifier is acquired and added with 1, 2 is addedRCalculating the result of the remainder;

When the calculation result is zero, determining that the instance does not continuously generate the resource of the identifier in the timing unit of the current time; or

And when the calculation result is not zero, determining that the instance has the resource for continuously generating the identifier in the timing unit where the current time is.

16. The apparatus according to claim 14, wherein the serial number obtaining module is specifically configured to:

when the first time information is different from the second time information, randomly determining any number of 0-9 as a serial number of the first identifier; or

when the first time information is the same as the second time information, adding 1 to the sequence number of the second identifier to obtain the sequence number of the first identifier.

17. An apparatus for generating an identifier, comprising:

A request receiving module for receiving a request for generating an identifier for a specific service;

An instance determination module to determine, in response to the request, one or more instances of the identifier generation service for the particular service; and

An identifier generation module configured to generate the first identifier according to the method of any one of claims 1 to 7 by using one of the one or more instances.

18. The apparatus of claim 17, further comprising:

a registration module to register the one or more instances to enable the one or more instances to have the capability to provide an identifier generation service for the particular service.

19. A system for generating an identifier, comprising:

One or more processors;

A storage device for storing one or more programs,

wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method of generating an identifier of any of claims 1-7.

20. A computer readable medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform a method of generating an identifier according to any of claims 1 to 7.

21. A system for generating an identifier, comprising:

One or more processors;

a storage device for storing one or more programs,

Wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to perform the method for generating an identifier of claim 8 or 9.

22. a computer readable medium having stored thereon executable instructions which, when executed by a processor, cause the processor to perform the method for generating an identifier according to claim 8 or 9.

35页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:信息查询的方法、装置、系统及介质

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!