wuid

package
v0.0.0-...-b4cee14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Overview

Example
newClient := func() (redis.UniversalClient, bool, error) {
	var client redis.UniversalClient
	// ...
	return client, true, nil
}

// Setup
g := NewWUID("default", nil)
_ = g.LoadH28FromRedis(newClient, "wuid")

// Generate
for i := 0; i < 10; i++ {
	fmt.Printf("%#016x\n", g.Next())
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NewClient

type NewClient func() (client redis.UniversalClient, autoDisconnect bool, err error)

type Option

type Option = v2.Option

func WithH28Verifier

func WithH28Verifier(cb func(h28 int64) error) Option

WithH28Verifier sets your own h28 verifier

func WithSection

func WithSection(section int8) Option

WithSection adds a section ID to the generated numbers. The section ID must be in between [0, 7].

func WithStep

func WithStep(step int64, floor int64) Option

WithStep sets the step and floor of Next()

type WUID

type WUID struct {
	// contains filtered or unexported fields
}

WUID is an extremely fast unique number generator.

func NewWUID

func NewWUID(name string, opts ...Option) *WUID

NewWUID creates a new WUID instance.

func (*WUID) LoadH28FromRedis

func (this *WUID) LoadH28FromRedis(newClient NewClient, key string) error

LoadH28FromRedis adds 1 to a specific number in your Redis, fetches its new value, and then sets that as the high 28 bits of the unique numbers that Next generates.

func (*WUID) Next

func (this *WUID) Next() int64

Next returns the next unique number.

func (*WUID) RenewNow

func (this *WUID) RenewNow() error

RenewNow reacquires the high 28 bits from your data store immediately

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL