paddy 1246fb0595 init | 2 سال پیش | |
---|---|---|
api | 2 سال پیش | |
client | 2 سال پیش | |
cmd | 2 سال پیش | |
configs | 2 سال پیش | |
entity | 2 سال پیش | |
library | 2 سال پیش | |
repository | 2 سال پیش | |
server | 2 سال پیش | |
service | 2 سال پیش | |
.gitignore | 2 سال پیش | |
LICENSE | 2 سال پیش | |
README.md | 2 سال پیش | |
gitconfig.sh | 2 سال پیش | |
go.mod | 2 سال پیش |
gid 是使用golang开发的生成分布式Id系统,基于数据库号段算法实现
go get github.com/hwholiday/gid/v2@gidV2
//go mod 内
//github.com/hwholiday/gid/v2 v2.0.6
package main
import (
"context"
"fmt"
gidSrv "github.com/hwholiday/gid/v2/api"
)
func main() {
cli, err := InitGrpc([]string{"127.0.0.1:2379"}, 15)
c, _ := cli.GetGidGrpcClient()
res, err := c.GetId(context.TODO(), &gidSrv.ReqId{
BizTag: "111",
})
fmt.Println(res, err)
}
create database gid;
use gid;
create table segments
(
biz_tag varchar(128) not null,
max_id bigint null,
step int null,
create_time bigint null,
update_time bigint null,
constraint segments_pk
primary key (biz_tag)
) ENGINE = InnoDB
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_bin;
go get github.com/hwholiday/gid/v2@gidV2 OR git clone -b gidV2 https://github.com/hwholiday/gid.git
cd gid/cmd
go build -o gid
./gid -conf ./gid.toml
BenchmarkService_GetId-4 2046296 583 ns/op
Begin
UPDATE table SET max_id=max_id+step WHERE biz_tag=xxx
SELECT tag, max_id, step FROM table WHERE biz_tag=xxx
Commit