Giter Site home page Giter Site logo

coderme / oneid Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 274 KB

Thread-safe concurrent, partially-sortable numeric IDs generator package for your app needs

Home Page: https://coderme.com

License: ISC License

Go 100.00%
id id-server golang-package golang

oneid's Introduction

ONEID - Distributable Unique numeric IDs

Features Summary

  • Thread-safe concurrent Numeric IDs.
  • Support upto 1024 servers with upto 32 processes each by default.
  • Partially-sortable time-based IDs.
  • Trivially customizable to support even more.
  • Uses only builtin Golang stdlib with no external dependencies.
  • Fully testable.
  • go.mod support.

You will love it if:

  • You believe numbers are IDs :)
  • You believe IDs creation should be wired to the app with no dependencies on any external ID servers.

Installation

  • The usal way, get it: go get github.com/coderme/oneid/v3

Usage

  • Generation of uint32 Id on a simple server with single process is as simple as:
id := oneid.Uint32(1,1 &oneid.DefaultUint32Config)
  • or better an uint64 if your database supports it
id := oneid.Uint64(1,1 &oneid.DefaultUint64Config)

Advanced Usage

  • You can Create a custom config in order to support upto 16,384 servers with 32 processes each.

conf := oneid.NewUint64Config(14, 5, 20)
id, err := EnvUint64()
if err != nil {
   // deal with the error
}

Benchmarks

go test -bench=. -benchmem

BenchmarkUint32-8        9375111               127.2 ns/op             0 B/op          0 allocs/op
BenchmarkUint64-8        9512419               128.2 ns/op             0 B/op          0 allocs/op
PASS
ok      github.com/coderme/oneid/v2     79.977s

Note: running test require at least 8GB and much cpu. be preapred with at least 16GB of free memory just in case :)

oneid's People

Contributors

coderme avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.