Skip to content

Latest commit

 

History

History
41 lines (29 loc) · 1.31 KB

README.md

File metadata and controls

41 lines (29 loc) · 1.31 KB

Seq

A globally, 64 bits, thread-safe identifier for Go. It can generate 4,194,303 numbers per second.

Introduction

┌--------┬--------┬--------┬--------┬--------┬--------┬--------┬--------┐
|11111111|11111111|11111111|11111111|11111111|11111111|11111111|11111111| FORMAT: 64 bits
├--------┼--------┼--------┼--------┼--------┼--------┼--------┼--------┤
|XXXXXXXX|XXXXXXXX|XXXXXXXX|XXXXXXXX|        |        |        |        | TIMESTAMP: 32 bits
├--------┼--------┼--------┼--------┼--------┼--------┼--------┼--------┤
|        |        |        |        |XXXXXXXX|XX      |        |        | WORKER ID: 10 bits
├--------┼--------┼--------┼--------┼--------┼--------┼--------┼--------┤
|        |        |        |        |        |  XXXXXX|XXXXXXXX|XXXXXXXX| SEQUENCE: 22 bits
└--------┴--------┴--------┴--------┴--------┴--------┴--------┴--------┘

Usage

New Seq

Create a new Seq with the worker identifier, and the worker identifier should be between 0 and 1023.

seq := NewSeq(0)
v := seq.Next()

Random Seq

Create a new Seq with a random worker identifier.

seq := RandomSeq()
v := seq.Next()

License

This project is under the MIT license. See the LICENSE file for details.