{"id":13694201,"url":"https://github.com/qichengzx/seqsvr","last_synced_at":"2026-01-27T17:05:44.931Z","repository":{"id":57523067,"uuid":"139127693","full_name":"qichengzx/seqsvr","owner":"qichengzx","description":"High performance unique number generator powered by Go","archived":false,"fork":false,"pushed_at":"2019-01-29T03:22:34.000Z","size":13,"stargazers_count":63,"open_issues_count":0,"forks_count":14,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-03T01:46:20.438Z","etag":null,"topics":["sequence"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qichengzx.png","metadata":{"files":{"readme":"README-zh_CN.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-29T09:10:12.000Z","updated_at":"2024-11-20T03:49:41.000Z","dependencies_parsed_at":"2022-08-28T08:12:32.197Z","dependency_job_id":null,"html_url":"https://github.com/qichengzx/seqsvr","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/qichengzx/seqsvr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qichengzx%2Fseqsvr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qichengzx%2Fseqsvr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qichengzx%2Fseqsvr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qichengzx%2Fseqsvr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qichengzx","download_url":"https://codeload.github.com/qichengzx/seqsvr/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qichengzx%2Fseqsvr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28816577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T12:25:15.069Z","status":"ssl_error","status_checked_at":"2026-01-27T12:25:05.297Z","response_time":168,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["sequence"],"created_at":"2024-08-02T17:01:26.549Z","updated_at":"2026-01-27T17:05:44.909Z","avatar_url":"https://github.com/qichengzx.png","language":"Go","funding_links":[],"categories":["开源类库","Open source library"],"sub_categories":["UUID"],"readme":"SEQSVR\n---------\n\n#### Go实现的全局唯一序列号生成服务\n\n[English](README.md)\n\n### 特性\n\n* 分布式：可任意横向扩展\n* 高性能：分配 ID 只访问内存(到达上限会请求数据库一次)\n* 易用性：对外提供 HTTP 服务\n* 唯一性：MySQL 自增 ID，永不重复\n* 高可靠：MySQL 持久化\n\n### 依赖项\n\n本项目使用下列优秀的项目作为必要组件。\n\n* gopkg.in/yaml.v2\n* github.com/go-sql-driver/mysql\n* github.com/satori/go.uuid\n\n### 安装\n\n**注意:需要在启动之前创建数据库并修改配置文件中数据库的配置。**\n\ngo get 方式：\n\n需保证 $GOPATH/bin 在系统 PATH 中。\n\n```shell\ngo get github.com/qichengzx/seqsvr\nseqsvr\n```\n单独编译：\n\n```shell\ngit clone git@github.com:qichengzx/seqsvr.git\ncd seqsvr\ngo build .\n./seqsvr\n```\nDocker 方式：\n\nDockerfile 使用了 Docker 多阶段构建功能，需保证 Docker 版本在 17.05 及以上。详见：[Use multi-stage builds](https://docs.docker.com/develop/develop-images/multistage-build/)\n\n```shell\ngit clone git@github.com:qichengzx/seqsvr.git\ncd seqsvr\ndocker build -t seqsvr:latest .\ndocker run -p 8000:8000 seqsvr:latest\n```\n\n### 初始化数据库\n\n数据库名称可以自定义，修改 config.yml 即可。\n\n然后导入以下 SQL 生成数据表。\n\n```mysql\nCREATE TABLE `generator_table` (\n  `id` int(11) NOT NULL AUTO_INCREMENT,\n  `uuid` char(36) NOT NULL COMMENT '机器识别码',\n  PRIMARY KEY (`id`),\n  UNIQUE KEY `id_UNIQUE` (`id`),\n  UNIQUE KEY `stub_UNIQUE` (`uuid`) USING BTREE\n) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n```\n\n### 修改配置\n\n配置文件使用 [YAML](http://yaml.org/) 格式。\n\n```yaml\n#app\nport: ':8000'\n\n#service\nstep: 100\n\n#db\nmysql:\n  user: 'root'\n  password: ''\n  host: 'tcp(localhost:3306)'\n  database: 'sequence'\n```\n\n可修改端口号及 MySQL 的配置。\n\n### 使用\n\n```shell\ncurl http://localhost:8000/new\n\n{\"code\":0,\"msg\":\"ok\",\"data\":{\"id\":101}}\n```\n\n### 原理\n\n本项目设计原理来自 携程技术中心 的[干货 | 分布式架构系统生成全局唯一序列号的一个思路](https://mp.weixin.qq.com/s/F7WTNeC3OUr76sZARtqRjw)。\n\n服务初始化后第一次请求会在 MySQL 数据库中插入一条数据，以生成初始 ID。\n\n后续的请求，都会在内存中进行自增返回，并且保证返回的 ID 不会超过设置的上限，到达上限后会再次从 MySQL 中更新数据，返回新的初始 ID 。\n\n##### 核心SQL\n\n```mysql\nREPLACE INTO `generator_table` (uuid) VALUES (\"54f5a3e2-e04c-4664-81db-d7f6a1259d01\");\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqichengzx%2Fseqsvr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqichengzx%2Fseqsvr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqichengzx%2Fseqsvr/lists"}