Skip to content
/ seq Public

A globally, 64 bits, thread-safe identifier for Go.

License

Notifications You must be signed in to change notification settings

yihleego/seq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

A globally, 64 bits, thread-safe identifier for Go.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages