snowflake

command module
v0.0.0-...-36fe82f Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2017 License: MIT Imports: 15 Imported by: 0

README

SNOWFLAKE

Build Status

设计理念

  1. 分布式uuid发生器,twitter snowflake的go语言版本
  2. 序列发生器

uuid格式为:

+-------------------------------------------------------------------------------------------------+
| UNUSED(1BIT) |         TIMESTAMP(41BIT)           |  MACHINE-ID(10BIT)  |   SERIAL-NO(12BIT)    |
+-------------------------------------------------------------------------------------------------+

安装

默认情况下uuid发生器依赖的snowflake-uuid键值对必须预先在etcd中创建,snowflake启动的时候会读取,例如:

   curl http://172.17.42.1:2379/v2/keys/seqs/snowflake-uuid -XPUT -d value="0"          

这个snowflake-uuid会用于MACHINE-ID的自动生成,如果完全由用户自定义machine_id,可以通过环境变量指定,如:

   export MACHINE_ID=123

如果要使用序列发生器Next(),必须预先创建一个key,例如:

   curl http://172.17.42.1:2379/v2/keys/seqs/userid -XPUT -d value="0"          

其他部分参考Dockerfile

使用

snowflake 参考测试用例和snowflake.proto

环境变量

ETCD_HOST: eg: http://172.17.42.1:2379
MACHINE_ID: eg: 123

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package proto is a generated protocol buffer package.
Package proto is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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