katsubushi(鰹節) is stand alone application to generate unique ID.
$ telnet localhost 11212
Trying ::1...
Connected to localhost.
Escape character is '^]'.
GET new
VALUE new 0 20
8070450532247928832
END
Download from releases or build from source code.
$ go get github.com/kayac/go-katsubushi/v2
$ cd $GOPATH/github.com/kayac/go-katsubushi
make
$ docker pull katsubushi/katsubushi
$ docker run -p 11212:11212 katsubushi/katsubushi -worker-id 1
$ docker run -p 11212:11212 katsubushi/katsubushi -redis redis://your.redis.host:6379/0
$ cd $GOPATH/github.com/kayac/go-katsubushi/cmd/katsubushi
./katsubushi -worker-id=1 -port=7238
./katsubushi -worker-id=1 -sock=/path/to/unix-domain.sock
katsubushi use protocol compatible with memcached.
Some commands are available with text and binary protocol.
But the others are available only with text protocol.
Binary protocol is also available only for single key GET.
GET id1 id2
VALUE id1 0 18
283890203179880448
VALUE id2 0 18
283890203179880449
END
VALUE(s) are unique IDs.
Returns a stats of katsubushi.
Binary protocol is also available.
STAT pid 8018
STAT uptime 17
STAT time 1487754986
STAT version 1.1.2
STAT curr_connections 1
STAT total_connections 2
STAT cmd_get 2
STAT get_hits 3
STAT get_misses 0
Returns a version of katsubushi.
Binary protocol is available, too.
VERSION 1.1.2
Disconnect an established connection.
katsubushi also runs an HTTP server specified with -http-port
.
Get a single ID.
When Accept
HTTP header is 'application/json', katsubushi will return an ID as JSON format as below.
{"id":"1025441401866821632"}
Otherwise, katsubushi will return ID as text format.
1025441401866821632
Get multiple IDs.
When Accept
HTTP header is 'application/json', katsubushi will return an IDs as JSON format as below.
{"ids":["1025442579472195584","1025442579472195585","1025442579472195586"]}
Otherwise, katsubushi will return ID as text format delimiterd with "\n".
1025442579472195584
1025442579472195585
1025442579472195586
Returns a stats of katsubushi.
This API returns a JSON always.
{
"pid": 1859630,
"uptime": 50,
"time": 1664761614,
"version": "1.8.0",
"curr_connections": 1,
"total_connections": 5,
"cmd_get": 15,
"get_hits": 25,
"get_misses": 0
}
katsubushi also runs an gRPC server specified with -grpc-port
.
See grpc/README.md.
katsubushi use algorithm like snowflake to generate ID.
-worker-id
or -redis
is required.
ID of the worker, must be unique in your service.
URL of Redis server. e.g. redis://example.com:6379/0
redis://{host}:{port}/{db}?ns={namespace}
If you are using Redis Cluster, you will need to specify the URL as rediscluster://{host}:{port}?ns={namespace}
.
This option is specified, katsubushi will assign an unique worker ID via Redis.
All katsubushi process for your service must use a same Redis URL.
These options work with -redis
.
If we use multi katsubushi clusters, worker-id range for each clusters must not be overlapped. katsubushi can specify the worker-id range by these options.
Optional.
Port number used for connection.
Default value is 11212
.
Optional. Path of unix doamin socket.
Optional.
Connection idle timeout in seconds.
0
means infinite.
Default value is 600
.
Optional.
Default value is info
.
Optional.
Boolean flag.
Enable profiling API by net/http/pprof
.
Endpoint is /debug/pprof
.
Optional.
Boolean flag.
Enable stats API by github.com/fukata/golang-stats-api-handler
.
Endpoint is /debug/stats
.
Optional.
Port number for listen http used for pprof
and stats
API.
Defalut value is 8080
.
Optional.
Port number of HTTP server.
Default value is 0
(disabled).
Optional.
Port number of gRPC server.
Default value is 0
(disabled).