1 Star 1 Fork 0

aping.fo / snowflake

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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

The MIT License (MIT) Copyright (c) 2015 gonet2 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

snowflake based on etcd 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/Aping-Fo/snowflake.git
git@gitee.com:Aping-Fo/snowflake.git
Aping-Fo
snowflake
snowflake
master

搜索帮助