paddy 1246fb0595 init | 2 anni fa | |
---|---|---|
api | 2 anni fa | |
client | 2 anni fa | |
cmd | 2 anni fa | |
configs | 2 anni fa | |
entity | 2 anni fa | |
library | 2 anni fa | |
repository | 2 anni fa | |
server | 2 anni fa | |
service | 2 anni fa | |
.gitignore | 2 anni fa | |
LICENSE | 2 anni fa | |
README.md | 2 anni fa | |
gitconfig.sh | 2 anni fa | |
go.mod | 2 anni fa |
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