All Projects → therne → Instauuid

therne / Instauuid

Licence: mit
Instagram-Style Compact UUID generator library for Node.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Instauuid

shortuuid.rb
Convert UUIDs & numbers into space efficient and URL-safe Base62 strings, or any other alphabet.
Stars: ✭ 38 (+22.58%)
Mutual labels:  uuid
Uuid
Generate and parse UUIDs.
Stars: ✭ 457 (+1374.19%)
Mutual labels:  uuid
Ordered Uuid
Reorganizes UUIDs for the purpose of fast indexing and searching by a database.
Stars: ✭ 5 (-83.87%)
Mutual labels:  uuid
Xyuuid
iOS14 UUID KeyChain DeviceInfo IDFA UDID
Stars: ✭ 301 (+870.97%)
Mutual labels:  uuid
Laravel Eloquent Uuid
A simple drop-in solution for providing UUID support for the IDs of your Eloquent models.
Stars: ✭ 388 (+1151.61%)
Mutual labels:  uuid
Shortuuid
🍄 A generator library for concise, unambiguous and URL-safe UUIDs
Stars: ✭ 603 (+1845.16%)
Mutual labels:  uuid
twitch-chat-visualizer
A Node.js Project. Would you like to see your chat stream with a custom design? This is for you!
Stars: ✭ 14 (-54.84%)
Mutual labels:  uuid
Session Token
Secure, efficient, simple random session token generation
Stars: ✭ 12 (-61.29%)
Mutual labels:  uuid
Go.uuid
UUID package for Go
Stars: ✭ 4,427 (+14180.65%)
Mutual labels:  uuid
Uuid Doctrine
Allow the use of a ramsey/uuid UUID as Doctrine field type.
Stars: ✭ 751 (+2322.58%)
Mutual labels:  uuid
Uniuri
Go package uniuri generates random strings good for use in URIs to identify unique objects.
Stars: ✭ 336 (+983.87%)
Mutual labels:  uuid
Go Nanoid
Golang random IDs generator.
Stars: ✭ 373 (+1103.23%)
Mutual labels:  uuid
Uuid Readable
Generate Easy to Remember, Readable UUIDs, that are Shakespearean and Grammatically Correct Sentences 🥳
Stars: ✭ 616 (+1887.1%)
Mutual labels:  uuid
Newid
A sequential id generator that works across nodes with no collisions
Stars: ✭ 255 (+722.58%)
Mutual labels:  uuid
Uuid
A UUID package originally forked from github.com/satori/go.uuid
Stars: ✭ 888 (+2764.52%)
Mutual labels:  uuid
cyksuid
Fast Python implementation of KSUID (K-Sortable Globally Unique IDs) using Cython
Stars: ✭ 29 (-6.45%)
Mutual labels:  uuid
Laravel Binary Uuid
Optimised binary UUIDs in Laravel
Stars: ✭ 523 (+1587.1%)
Mutual labels:  uuid
Node Scalable Blob Store
A file system blob store that is designed to prevent conflicts when used with a distributed file system or storage area network
Stars: ✭ 31 (+0%)
Mutual labels:  uuid
Go Uuid
A wrapper for Linux kernel UUID v4 generator.
Stars: ✭ 26 (-16.13%)
Mutual labels:  uuid
Timeflake
Timeflake is a 128-bit, roughly-ordered, URL-safe UUID.
Stars: ✭ 669 (+2058.06%)
Mutual labels:  uuid

InstaUUID

NPM Version Node.js Version NPM Downloads

See Instagram Engineering Blog - Sharding IDs at Instagram

Instagram-Style Compact UUID generator for Node.js.

Generates 8-byte UUID that consists of:

  • 41 bits for time in milliseconds (we can use it until 2084/09/06 lunch time comes)
  • 13 bits for additional information - Instagram used it to store the logical shard ID
  • 10 bits that represent an auto-incrementing sequence.
  • Note that you need to implement your own counter per machine - In default, we fill
    this space with random values.

Benefits of this library:

  • Qualified - Because this library implements Instagram UUID Spec. and instagram rocks.
  • Compact Size - The raw hash is only 8bytes, and Base64 hash is only 11 bytes!
  • URL-Safe - The default Base64 encoding does not contain URL-non-safe characters.

Installation

$ npm install --save instauuid

Examples

var instauuid = require('instauuid');

instauuid(); // Default: Base64 - ex) "paZhL98FBXs"
instauuid('hex'); // Hex String - ex) "a5afe16d768b4cdf"
instauuid('decimal'); // Decimal String - ex) "11939009410687035132"

// Using InstaUUID with MySQL
// See "Integrating with your database" Section.
var sql = 'INSERT INTO users (id, name) VALUES (??, ??)';
sql = mysql.format(instauuid('decimal'), 'John Doe');

// You can add some information to prevent hash conflicts. (recommended for big systems)
instauuid({ type: 'hex', additional: shardId, countNumber: 1022 });

Integrating with your database

MySQL

First, You need to set your primary key datatype to UNSIGNED BIGINT.

CREATE TABLE foo (
   id   BIGINT UNSIGNED NOT NULL UNIQUE PRIMARY KEY,
   ....
);

#####node-mysql Driver

  • Set 'supportBigNumbers', 'bigNumberStrings' options to true when connecting.
  • This option makes you to read BIGINT as String, because UUID is too big that
    JavaScript Number type cannot support. Number can handle up to 2^53 but we're using 2^64 range (Unsigned Int64)
  • I recommend to use Long or bignumber.js Library when handling BIGINT data.
  • Use 'decimal' type when generating UUID. (See above example)

Redis

Redis stores Integer as String, so you don't need to worry about anything.

MongoDB

Just use MongoDB ObjectId.

Documentation

instauuid(options)

Generates and returns UUID.

  • options (object || string): Generating options. (or return type)
Option Description Range Default
type Return type of generated ID. See below for more details. - 'base64'
additional Additional Unique Information (ex: Logical Shard ID) 0 ~ 8191 (current time as μs)
countNumber Auto-incrementing sequence - to prevent conflicting 0 ~ 1023 (Random)
Return types
Name Description Type
base64 Base64 Hash (Note that this is not pure Base64. We uses URL-Safe Base64URL) String
decimal Decimal String String
number (Same as above) -
hex Hex String String
hash (Same as above) -
long Long object Long
buffer Buffer object Buffer
buffer_be Big-Endian encoded buffer Buffer
raw Raw ASCII Bytes - Don't recommend. String

License: MIT

Author: Hyojun Kim

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].