Based on the Snowflake Global ID Generator Go-id-worker

Source: Internet
Author: User
Tags unique id
This is a created article in which the information may have evolved or changed. The structure of the snowflake is as follows (each part with-separate): 0-0000000000 0000000000 0000000000 0000000000 0-00000-00000-000000000000 The first bit is unused and the next 41 bits are milliseconds Level time (41-bit lengths can be used for 69 years), followed by 5-bit datacenterid and 5-bit Workerid (10-bit lengths support deployment of up to 1024 nodes), The last 12 bits are counted in milliseconds (the 12-bit count order number supports each node producing 4,096 ID numbers per millisecond) altogether adding up to exactly 64 bits, for a long type. The IDs generated by the snowflake (up to the length of the string) are sorted by time, and the IDs collisions (which are differentiated by datacenter and Workerid) are not generated in the entire distributed system, and are more efficient. Tested snowflake can generate 260,000 IDs per second. # Go-id-workeridworker in Golang.go-id-worker are an ID creator. For generating a global unique ID. The type of ID is int64.## your can get it like this. ' Go get ' github.com/gitstliu/go-id-worker ' ' # # # and import it like T His. ' Import ("Github.com/gitstliu/go-id-worker") "# # # Create and use a idworker like this. ' Currwoker: = &idwork Er. idworker{} currwoker.initidworker (1) NewId: = Currwoker.nexiid () "236 reads ∙1 likes
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.