Documentation
¶
Index ¶
- Variables
- func EncodeBatchDelete(key []byte) []byte
- func EncodeBatchPut(key, value []byte) []byte
- func ListenOn(addr string) (net.Listener, error)
- func RegisterKVServiceServer(s *grpc.Server, srv KVServiceServer)
- func Start(addr string, db *knocidb.DB, opts ...grpc.ServerOption) (*grpc.Server, net.Listener, error)
- func StartSecure(addr string, db *knocidb.DB, sec ServerSecurityOptions, ...) (*grpc.Server, net.Listener, error)
- type Client
- func (c *Client) Batch(ctx context.Context, ops [][]byte, opts ...grpc.CallOption) error
- func (c *Client) Close() error
- func (c *Client) Delete(ctx context.Context, key []byte, opts ...grpc.CallOption) error
- func (c *Client) Get(ctx context.Context, key []byte, opts ...grpc.CallOption) ([]byte, error)
- func (c *Client) Put(ctx context.Context, key, value []byte, opts ...grpc.CallOption) error
- func (c *Client) Scan(ctx context.Context, start, end []byte, fn func(key, value []byte) bool, ...) error
- type ClientSecurityOptions
- type KVServiceClient
- type KVServiceServer
- type KVService_BatchClient
- type KVService_BatchServer
- type KVService_ScanClient
- type KVService_ScanServer
- type Server
- func (s *Server) Batch(stream KVService_BatchServer) error
- func (s *Server) Delete(ctx context.Context, in *wrapperspb.BytesValue) (*emptypb.Empty, error)
- func (s *Server) Get(ctx context.Context, in *wrapperspb.BytesValue) (*wrapperspb.BytesValue, error)
- func (s *Server) Put(ctx context.Context, in *wrapperspb.BytesValue) (*emptypb.Empty, error)
- func (s *Server) Scan(in *wrapperspb.BytesValue, stream KVService_ScanServer) error
- type ServerSecurityOptions
Constants ¶
This section is empty.
Variables ¶
View Source
var KVService_ServiceDesc = grpc.ServiceDesc{ ServiceName: "knocidb.KVService", HandlerType: (*KVServiceServer)(nil), Methods: []grpc.MethodDesc{ { MethodName: "Get", Handler: _KVService_Get_Handler, }, { MethodName: "Put", Handler: _KVService_Put_Handler, }, { MethodName: "Delete", Handler: _KVService_Delete_Handler, }, }, Streams: []grpc.StreamDesc{ { StreamName: "Batch", Handler: _KVService_Batch_Handler, ClientStreams: true, }, { StreamName: "Scan", Handler: _KVService_Scan_Handler, ServerStreams: true, }, }, Metadata: "grpc/kv.proto", }
Functions ¶
func EncodeBatchDelete ¶
EncodeBatchDelete 将一条 Delete 操作编码为批处理载荷
func EncodeBatchPut ¶
EncodeBatchPut 将一条 Put 操作编码为批处理载荷
func RegisterKVServiceServer ¶
func RegisterKVServiceServer(s *grpc.Server, srv KVServiceServer)
RegisterKVServiceServer 注册 KVService 到 gRPC Server
func Start ¶
func Start(addr string, db *knocidb.DB, opts ...grpc.ServerOption) (*grpc.Server, net.Listener, error)
Start 在指定地址启动 gRPC 服务 可通过 opts 传入 TLS/拦截器等配置
func StartSecure ¶
func StartSecure(addr string, db *knocidb.DB, sec ServerSecurityOptions, extra ...grpc.ServerOption) (*grpc.Server, net.Listener, error)
StartSecure 启动启用了 TLS/鉴权的 gRPC 服务
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func Dial ¶
func Dial(addr string, opts ...grpc.DialOption) (*Client, error)
Dial 以默认配置建立到 gRPC 服务的连接(默认 insecure)
func DialSecure ¶
func DialSecure(addr string, sec ClientSecurityOptions, extra ...grpc.DialOption) (*Client, error)
DialSecure 建立启用了 TLS/鉴权的客户端连接
type ClientSecurityOptions ¶
type ClientSecurityOptions struct {
TLSCACertFile string
TLSServerName string
ClientCertFile string
ClientKeyFile string
EnableAuth bool
AuthToken string
}
ClientSecurityOptions 指定客户端的 TLS 与鉴权配置
type KVServiceClient ¶
type KVServiceClient interface {
Get(context.Context, *wrapperspb.BytesValue, ...grpc.CallOption) (*wrapperspb.BytesValue, error)
Put(context.Context, *wrapperspb.BytesValue, ...grpc.CallOption) (*emptypb.Empty, error)
Delete(context.Context, *wrapperspb.BytesValue, ...grpc.CallOption) (*emptypb.Empty, error)
// Batch 客户端流:发送多条 Put/Delete 操作
Batch(context.Context, ...grpc.CallOption) (KVService_BatchClient, error)
// Scan 服务端流:按范围返回 KV
Scan(context.Context, *wrapperspb.BytesValue, ...grpc.CallOption) (KVService_ScanClient, error)
}
func NewKVServiceClient ¶
func NewKVServiceClient(cc grpc.ClientConnInterface) KVServiceClient
type KVServiceServer ¶
type KVServiceServer interface {
Get(context.Context, *wrapperspb.BytesValue) (*wrapperspb.BytesValue, error)
Put(context.Context, *wrapperspb.BytesValue) (*emptypb.Empty, error)
Delete(context.Context, *wrapperspb.BytesValue) (*emptypb.Empty, error)
// Batch 客户端流:接收多条操作(Put/Delete),在服务端批量提交
Batch(KVService_BatchServer) error
// Scan 服务端流:在B+Tree模式下按范围扫描并流式返回KV
Scan(*wrapperspb.BytesValue, KVService_ScanServer) error
}
type KVService_BatchClient ¶
type KVService_BatchClient interface {
Send(*wrapperspb.BytesValue) error
CloseAndRecv() (*emptypb.Empty, error)
grpc.ClientStream
}
KVService_BatchClient 客户端流:向服务端发送批处理操作
type KVService_BatchServer ¶
type KVService_BatchServer interface {
SendAndClose(*emptypb.Empty) error
Recv() (*wrapperspb.BytesValue, error)
grpc.ServerStream
}
type KVService_ScanClient ¶
type KVService_ScanClient interface {
Recv() (*wrapperspb.BytesValue, error)
grpc.ClientStream
}
type KVService_ScanServer ¶
type KVService_ScanServer interface {
Send(*wrapperspb.BytesValue) error
grpc.ServerStream
}
type Server ¶
type Server struct {
// EnableAuth 指示是否启用基于 token 的鉴权
EnableAuth bool
// AuthToken 服务端校验的令牌(通过 metadata: authorization / x-api-key 传入)
AuthToken string
// contains filtered or unexported fields
}
func (*Server) Batch ¶
func (s *Server) Batch(stream KVService_BatchServer) error
Batch 客户端流:接收多条操作并批量提交
func (*Server) Delete ¶
func (s *Server) Delete(ctx context.Context, in *wrapperspb.BytesValue) (*emptypb.Empty, error)
Delete 删除指定 key
func (*Server) Get ¶
func (s *Server) Get(ctx context.Context, in *wrapperspb.BytesValue) (*wrapperspb.BytesValue, error)
Get 读取指定 key 的值
func (*Server) Put ¶
func (s *Server) Put(ctx context.Context, in *wrapperspb.BytesValue) (*emptypb.Empty, error)
Put 写入一条 key/value(payload 自定义二进制:uint32 key_len | key | value)
func (*Server) Scan ¶
func (s *Server) Scan(in *wrapperspb.BytesValue, stream KVService_ScanServer) error
Scan 服务端流:在B+Tree模式下按范围扫描并流式返回KV 请求载荷:uint32 start_len | start | uint32 end_len | end
Click to show internal directories.
Click to hide internal directories.