diff --git a/pkg/lru/define.go b/pkg/lru/define.go index 2eb64ef..2f90447 100644 --- a/pkg/lru/define.go +++ b/pkg/lru/define.go @@ -1,3 +1,5 @@ package lru -// define +import "gitee.com/timedb/wheatCache/pkg/structure" + +type SingleWorkFunc func() (*structure.ResultConn, error) diff --git a/pkg/proto/stringx.pb.go b/pkg/proto/stringx.pb.go index 58c2e40..07b5ab7 100644 --- a/pkg/proto/stringx.pb.go +++ b/pkg/proto/stringx.pb.go @@ -26,6 +26,7 @@ type SetRequest struct { unknownFields protoimpl.UnknownFields Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Val string `protobuf:"bytes,2,opt,name=val,proto3" json:"val,omitempty"` } func (x *SetRequest) Reset() { @@ -67,6 +68,13 @@ func (x *SetRequest) GetKey() *BaseKey { return nil } +func (x *SetRequest) GetVal() string { + if x != nil { + return x.Val + } + return "" +} + type GetRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -120,6 +128,8 @@ type AddRequest struct { unknownFields protoimpl.UnknownFields Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // 自动增加 + Raise int32 `protobuf:"varint,2,opt,name=raise,proto3" json:"raise,omitempty"` } func (x *AddRequest) Reset() { @@ -161,12 +171,20 @@ func (x *AddRequest) GetKey() *BaseKey { return nil } +func (x *AddRequest) GetRaise() int32 { + if x != nil { + return x.Raise + } + return 0 +} + type ReduceRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Cut int32 `protobuf:"varint,2,opt,name=cut,proto3" json:"cut,omitempty"` } func (x *ReduceRequest) Reset() { @@ -208,12 +226,21 @@ func (x *ReduceRequest) GetKey() *BaseKey { return nil } +func (x *ReduceRequest) GetCut() int32 { + if x != nil { + return x.Cut + } + return 0 +} + type SetbitRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Office int32 `protobuf:"varint,2,opt,name=office,proto3" json:"office,omitempty"` + Val bool `protobuf:"varint,3,opt,name=val,proto3" json:"val,omitempty"` } func (x *SetbitRequest) Reset() { @@ -255,12 +282,27 @@ func (x *SetbitRequest) GetKey() *BaseKey { return nil } +func (x *SetbitRequest) GetOffice() int32 { + if x != nil { + return x.Office + } + return 0 +} + +func (x *SetbitRequest) GetVal() bool { + if x != nil { + return x.Val + } + return false +} + type GetbitRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Key *BaseKey `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + Office int32 `protobuf:"varint,2,opt,name=office,proto3" json:"office,omitempty"` } func (x *GetbitRequest) Reset() { @@ -302,29 +344,44 @@ func (x *GetbitRequest) GetKey() *BaseKey { return nil } +func (x *GetbitRequest) GetOffice() int32 { + if x != nil { + return x.Office + } + return 0 +} + var File_stringx_proto protoreflect.FileDescriptor var file_stringx_proto_rawDesc = []byte{ 0x0a, 0x0d, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x78, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x1a, - 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x28, 0x0a, 0x0a, 0x53, + 0x0a, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3a, 0x0a, 0x0a, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, - 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x28, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, - 0x28, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, - 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, - 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x52, 0x65, 0x64, - 0x75, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, - 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, - 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x62, 0x69, 0x74, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, - 0x6b, 0x65, 0x79, 0x22, 0x2b, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x62, 0x69, 0x74, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, - 0x42, 0x0b, 0x5a, 0x09, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x28, 0x0a, 0x0a, 0x47, 0x65, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, + 0x79, 0x22, 0x3e, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, + 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x72, + 0x61, 0x69, 0x73, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x72, 0x61, 0x69, 0x73, + 0x65, 0x22, 0x3d, 0x0a, 0x0d, 0x52, 0x65, 0x64, 0x75, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x10, + 0x0a, 0x03, 0x63, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x63, 0x75, 0x74, + 0x22, 0x55, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x62, 0x69, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, + 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, + 0x06, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6f, + 0x66, 0x66, 0x69, 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x76, 0x61, 0x6c, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x03, 0x76, 0x61, 0x6c, 0x22, 0x43, 0x0a, 0x0d, 0x47, 0x65, 0x74, 0x62, 0x69, + 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x08, 0x2e, 0x42, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x52, + 0x03, 0x6b, 0x65, 0x79, 0x12, 0x16, 0x0a, 0x06, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x6f, 0x66, 0x66, 0x69, 0x63, 0x65, 0x42, 0x0b, 0x5a, 0x09, + 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x33, } var ( diff --git a/pkg/structure/generate/interface.template b/pkg/structure/generate/interface.template index 97c0780..e82e2de 100644 --- a/pkg/structure/generate/interface.template +++ b/pkg/structure/generate/interface.template @@ -22,7 +22,7 @@ type KeyBaseInterface interface { type {{key}}Interface interface{ KeyBaseInterface {% for val in value -%} - {{val}}(*proto.{{val}}Request) ([]string, error) + {{val}}(*proto.{{val}}Request) (*ResultConn, error) {% endfor %} } {% endfor -%} diff --git a/pkg/structure/generate/storage.template b/pkg/structure/generate/storage.template new file mode 100644 index 0000000..b9c6d7a --- /dev/null +++ b/pkg/structure/generate/storage.template @@ -0,0 +1,45 @@ +// TODO 添加 storage server 模板 +package server + +import ( + context "context" + "gitee.com/timedb/wheatCache/pkg/proto" +) + +type server struct { +} + +func NewServer() proto.CommServerServer { + ser := &server{} + return ser +} + +func (s *server) Get( + cxt context.Context, + req *proto.GetRequest, +) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Set( + ctx context.Context, + req *proto.SetRequest, +) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Add(ctx context.Context, request *proto.AddRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Reduce(ctx context.Context, request *proto.ReduceRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Setbit(ctx context.Context, request *proto.SetbitRequest) (*proto.CommendResponse, error) { + panic("implement me") +} + +func (s *server) Getbit(ctx context.Context, request *proto.GetbitRequest) (*proto.CommendResponse, error) { + panic("implement me") +} diff --git a/pkg/structure/interface.gen.go b/pkg/structure/interface.gen.go index ba53360..b25cbe1 100644 --- a/pkg/structure/interface.gen.go +++ b/pkg/structure/interface.gen.go @@ -20,10 +20,10 @@ type KeyBaseInterface interface { type StringXInterface interface { KeyBaseInterface - Set(*proto.SetRequest) ([]string, error) - Get(*proto.GetRequest) ([]string, error) - Add(*proto.AddRequest) ([]string, error) - Reduce(*proto.ReduceRequest) ([]string, error) - Setbit(*proto.SetbitRequest) ([]string, error) - Getbit(*proto.GetbitRequest) ([]string, error) + Set(*proto.SetRequest) (*ResultConn, error) + Get(*proto.GetRequest) (*ResultConn, error) + Add(*proto.AddRequest) (*ResultConn, error) + Reduce(*proto.ReduceRequest) (*ResultConn, error) + Setbit(*proto.SetbitRequest) (*ResultConn, error) + Getbit(*proto.GetbitRequest) (*ResultConn, error) } diff --git a/pkg/structure/stringx/string.go b/pkg/structure/stringx/string.go index 7a86a05..4e7ac6f 100644 --- a/pkg/structure/stringx/string.go +++ b/pkg/structure/stringx/string.go @@ -1,51 +1,63 @@ package stringx -import "gitee.com/timedb/wheatCache/pkg/proto" +import ( + "gitee.com/timedb/wheatCache/pkg/proto" + "gitee.com/timedb/wheatCache/pkg/structure" +) -type StringX struct { - Value string +type StringSingle struct { + val *structure.Value } -func (s *StringX) SizeByte() int64 { - panic("implement me") +func NewStringSingle() structure.StringXInterface { + return &StringSingle{ + val: structure.NewValue(), + } } -func (s *StringX) RollBack() error { - panic("implement me") +func (s *StringSingle) SizeByte() int64 { + return int64(s.val.GetLength()) } -func (s *StringX) Begin() error { - panic("implement me") +// TODO RollBack 事务相关, V2 实现 +func (s *StringSingle) RollBack() error { + panic("not implemented") // TODO: Implement } -func (s *StringX) Comment() error { - panic("implement me") +// Begin 事务相关, V2 实现 +func (s *StringSingle) Begin() error { + panic("not implemented") // TODO: Implement } -func (s *StringX) Encode() ([]byte, error) { - panic("implement me") +// Comment 事务相关, V2 实现 +func (s *StringSingle) Comment() error { + panic("not implemented") // TODO: Implement } -func (s *StringX) Set(req *proto.SetRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Encode() ([]byte, error) { + panic("not implemented") // TODO: Implement } -func (s *StringX) Get(req *proto.GetRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Set(req *proto.SetRequest) (*structure.ResultConn, error) { + return nil, nil } -func (s *StringX) Add(req *proto.AddRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Get(req *proto.GetRequest) (*structure.ResultConn, error) { + panic("not implemented") // TODO: Implement } -func (s *StringX) Reduce(req *proto.ReduceRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Add(req *proto.AddRequest) (*structure.ResultConn, error) { + panic("not implemented") // TODO: Implement } -func (s *StringX) Setbit(req *proto.SetbitRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Reduce(req *proto.ReduceRequest) (*structure.ResultConn, error) { + panic("not implemented") // TODO: Implement } -func (s *StringX) Getbit(req *proto.GetbitRequest) ([]string, error) { - panic("implement me") +func (s *StringSingle) Setbit(req *proto.SetbitRequest) (*structure.ResultConn, error) { + panic("not implemented") // TODO: Implement +} + +func (s *StringSingle) Getbit(req *proto.GetbitRequest) (*structure.ResultConn, error) { + panic("not implemented") // TODO: Implement } diff --git a/pkg/structure/stringx/string_test.go b/pkg/structure/stringx/string_test.go new file mode 100644 index 0000000..4150247 --- /dev/null +++ b/pkg/structure/stringx/string_test.go @@ -0,0 +1,19 @@ +package stringx + +import ( + "fmt" + "gitee.com/timedb/wheatCache/pkg/proto" + "github.com/stretchr/testify/require" + "testing" +) + +func TestStringSingle_Set(t *testing.T) { + s := new(StringSingle) + p := s.SizeByte() + require.Equal(t, p, int64(16)) + s.Set(&proto.SetRequest{ + Val: "", + }) + p = s.SizeByte() + fmt.Println(p) +} diff --git a/protobuf/stringx.proto b/protobuf/stringx.proto index 3c1ca5d..01cb72b 100644 --- a/protobuf/stringx.proto +++ b/protobuf/stringx.proto @@ -4,6 +4,7 @@ option go_package = "pkg/proto"; message SetRequest { BaseKey key = 1; + string val = 2; } message GetRequest { @@ -12,16 +13,22 @@ message GetRequest { message AddRequest { BaseKey key = 1; + // 自动增加 + int32 raise = 2; } message ReduceRequest { BaseKey key = 1; + int32 cut = 2; } message SetbitRequest { BaseKey key = 1; + int32 office = 2; + bool val = 3; } message GetbitRequest { BaseKey key = 1; + int32 office = 2; }