Documentation
¶
Overview ¶
Package monoton is a highly scalable, single/multi node, human-readable, predictable and incremental unique id generator
Time Ordered ¶
The monoton package provides sequences based on the monotonic time which represents the absolute elapsed wall-clock time since some arbitrary, fixed point in the past. It isn't affected by changes in the system time-of-day clock.
Initial Time ¶
Initial time value opens space for the time value by subtracting the given value from the time sequence.
Readable ¶
The monoton package converts all sequences into Base62 format. And Base62 only uses ASCII alpha-numeric chars to represent data which makes it easy to read, predict the order by a human eye.
The total byte size is fixed to 16 bytes for all sequencers. And at least one byte is reserved to nodes.
Multi Node Support ¶
The monoton package can be used on single/multiple nodes without the need for machine coordination. It uses configured node identifier to generate ids by attaching the node identifier to the end of the sequences.
Extendable ¶
The package comes with three pre-configured sequencers and Sequencer interface to allow new sequencers.
Included Sequencers and Byte Orderings ¶
The monoton package currently comes with Nanosecond, Millisecond and Second sequencers. And it uses Millisecond sequencer by default. For each sequencer, the byte orders are as following:
Second: 16 B => 6 B (seconds) + 6 B (counter) + 4 B (node) Millisecond: 16 B => 8 B (milliseconds) + 4 B (counter) + 4 B (node) Nanosecond: 16 B => 11 B (nanoseconds) + 2 B (counter) + 3 B (node)
New Sequencers ¶
The sequencers can be extended for any other time format, sequence format by implementing the monoton/sequncer.Sequencer interface.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Configure ¶
Configure configures the monoton with the given generator and node. If you need to reset the node, then you have to reconfigure. If you do not configure the node then the node will be set to zero value.
Example ¶
package main
import (
"fmt"
"github.com/mustafaturan/monoton"
"github.com/mustafaturan/monoton/sequencer"
)
func main() {
s := sequencer.NewMillisecond() // has 4 bytes free space for a node
n := uint(19) // Base62 => J
t := uint(0) // initial time (start from unix time in ms)
monoton.Configure(s, n, t)
fmt.Println(monoton.Next()[12:])
}
Output: 000J
func Next ¶
func Next() string
Next generates next incremental unique identifier as Base62 The execution will return the following Bytes (B) for the known sequencer types:
Second: 16 B => 6 B (seconds) + 6 B (counter) + 4 B (node) Millisecond: 16 B => 8 B (milliseconds) + 4 B (counter) + 4 B (node) Nanosecond: 16 B => 11 B (nanoseconds) + 2 B (counter) + 3 B (node)
For byte size decisions please refer to docs/adrs/byte-sizes.md
Example ¶
package main
import (
"fmt"
"time"
"github.com/mustafaturan/monoton"
"github.com/mustafaturan/monoton/sequencer"
)
func main() {
s := sequencer.NewSecond() // sequencer.Second
n := uint(19) // Base62 => J
t := uint(time.Now().Unix()) // initial time (start from unix time in s)
monoton.Configure(s, n, t)
fmt.Println(len(monoton.Next()))
}
Output: 16
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package encoder provides encoding functionality for Base10 to Base62 convertion with/without paddings
|
Package encoder provides encoding functionality for Base10 to Base62 convertion with/without paddings |
|
Package sequencer provides sequences based on monotonic time Time The sequncer package provides sequences based on the monotonic time which represents the absolute elapsed wall-clock time since some arbitrary, fixed point in the past.
|
Package sequencer provides sequences based on monotonic time Time The sequncer package provides sequences based on the monotonic time which represents the absolute elapsed wall-clock time since some arbitrary, fixed point in the past. |