Change the store interface to remove variadic args (#1095)
This commit is contained in:
@@ -78,18 +78,58 @@ func (m *Record) GetExpiry() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"`
|
||||
type ReadOptions struct {
|
||||
Prefix bool `protobuf:"varint,1,opt,name=prefix,proto3" json:"prefix,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ReadOptions) Reset() { *m = ReadOptions{} }
|
||||
func (m *ReadOptions) String() string { return proto.CompactTextString(m) }
|
||||
func (*ReadOptions) ProtoMessage() {}
|
||||
func (*ReadOptions) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{1}
|
||||
}
|
||||
|
||||
func (m *ReadOptions) XXX_Unmarshal(b []byte) error {
|
||||
return xxx_messageInfo_ReadOptions.Unmarshal(m, b)
|
||||
}
|
||||
func (m *ReadOptions) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||
return xxx_messageInfo_ReadOptions.Marshal(b, m, deterministic)
|
||||
}
|
||||
func (m *ReadOptions) XXX_Merge(src proto.Message) {
|
||||
xxx_messageInfo_ReadOptions.Merge(m, src)
|
||||
}
|
||||
func (m *ReadOptions) XXX_Size() int {
|
||||
return xxx_messageInfo_ReadOptions.Size(m)
|
||||
}
|
||||
func (m *ReadOptions) XXX_DiscardUnknown() {
|
||||
xxx_messageInfo_ReadOptions.DiscardUnknown(m)
|
||||
}
|
||||
|
||||
var xxx_messageInfo_ReadOptions proto.InternalMessageInfo
|
||||
|
||||
func (m *ReadOptions) GetPrefix() bool {
|
||||
if m != nil {
|
||||
return m.Prefix
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
type ReadRequest struct {
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
Options *ReadOptions `protobuf:"bytes,2,opt,name=options,proto3" json:"options,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *ReadRequest) Reset() { *m = ReadRequest{} }
|
||||
func (m *ReadRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ReadRequest) ProtoMessage() {}
|
||||
func (*ReadRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{1}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{2}
|
||||
}
|
||||
|
||||
func (m *ReadRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -110,9 +150,16 @@ func (m *ReadRequest) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_ReadRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *ReadRequest) GetKeys() []string {
|
||||
func (m *ReadRequest) GetKey() string {
|
||||
if m != nil {
|
||||
return m.Keys
|
||||
return m.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (m *ReadRequest) GetOptions() *ReadOptions {
|
||||
if m != nil {
|
||||
return m.Options
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -128,7 +175,7 @@ func (m *ReadResponse) Reset() { *m = ReadResponse{} }
|
||||
func (m *ReadResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ReadResponse) ProtoMessage() {}
|
||||
func (*ReadResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{2}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{3}
|
||||
}
|
||||
|
||||
func (m *ReadResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -157,17 +204,17 @@ func (m *ReadResponse) GetRecords() []*Record {
|
||||
}
|
||||
|
||||
type WriteRequest struct {
|
||||
Records []*Record `protobuf:"bytes,2,rep,name=records,proto3" json:"records,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
Record *Record `protobuf:"bytes,1,opt,name=record,proto3" json:"record,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
}
|
||||
|
||||
func (m *WriteRequest) Reset() { *m = WriteRequest{} }
|
||||
func (m *WriteRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*WriteRequest) ProtoMessage() {}
|
||||
func (*WriteRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{3}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{4}
|
||||
}
|
||||
|
||||
func (m *WriteRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -188,9 +235,9 @@ func (m *WriteRequest) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_WriteRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *WriteRequest) GetRecords() []*Record {
|
||||
func (m *WriteRequest) GetRecord() *Record {
|
||||
if m != nil {
|
||||
return m.Records
|
||||
return m.Record
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -205,7 +252,7 @@ func (m *WriteResponse) Reset() { *m = WriteResponse{} }
|
||||
func (m *WriteResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*WriteResponse) ProtoMessage() {}
|
||||
func (*WriteResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{4}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{5}
|
||||
}
|
||||
|
||||
func (m *WriteResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -227,7 +274,7 @@ func (m *WriteResponse) XXX_DiscardUnknown() {
|
||||
var xxx_messageInfo_WriteResponse proto.InternalMessageInfo
|
||||
|
||||
type DeleteRequest struct {
|
||||
Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"`
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -237,7 +284,7 @@ func (m *DeleteRequest) Reset() { *m = DeleteRequest{} }
|
||||
func (m *DeleteRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*DeleteRequest) ProtoMessage() {}
|
||||
func (*DeleteRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{5}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{6}
|
||||
}
|
||||
|
||||
func (m *DeleteRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -258,11 +305,11 @@ func (m *DeleteRequest) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_DeleteRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *DeleteRequest) GetKeys() []string {
|
||||
func (m *DeleteRequest) GetKey() string {
|
||||
if m != nil {
|
||||
return m.Keys
|
||||
return m.Key
|
||||
}
|
||||
return nil
|
||||
return ""
|
||||
}
|
||||
|
||||
type DeleteResponse struct {
|
||||
@@ -275,7 +322,7 @@ func (m *DeleteResponse) Reset() { *m = DeleteResponse{} }
|
||||
func (m *DeleteResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*DeleteResponse) ProtoMessage() {}
|
||||
func (*DeleteResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{6}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{7}
|
||||
}
|
||||
|
||||
func (m *DeleteResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -297,8 +344,6 @@ func (m *DeleteResponse) XXX_DiscardUnknown() {
|
||||
var xxx_messageInfo_DeleteResponse proto.InternalMessageInfo
|
||||
|
||||
type ListRequest struct {
|
||||
// optional key
|
||||
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
XXX_unrecognized []byte `json:"-"`
|
||||
XXX_sizecache int32 `json:"-"`
|
||||
@@ -308,7 +353,7 @@ func (m *ListRequest) Reset() { *m = ListRequest{} }
|
||||
func (m *ListRequest) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListRequest) ProtoMessage() {}
|
||||
func (*ListRequest) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{7}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{8}
|
||||
}
|
||||
|
||||
func (m *ListRequest) XXX_Unmarshal(b []byte) error {
|
||||
@@ -329,13 +374,6 @@ func (m *ListRequest) XXX_DiscardUnknown() {
|
||||
|
||||
var xxx_messageInfo_ListRequest proto.InternalMessageInfo
|
||||
|
||||
func (m *ListRequest) GetKey() string {
|
||||
if m != nil {
|
||||
return m.Key
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ListResponse struct {
|
||||
Records []*Record `protobuf:"bytes,1,rep,name=records,proto3" json:"records,omitempty"`
|
||||
XXX_NoUnkeyedLiteral struct{} `json:"-"`
|
||||
@@ -347,7 +385,7 @@ func (m *ListResponse) Reset() { *m = ListResponse{} }
|
||||
func (m *ListResponse) String() string { return proto.CompactTextString(m) }
|
||||
func (*ListResponse) ProtoMessage() {}
|
||||
func (*ListResponse) Descriptor() ([]byte, []int) {
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{8}
|
||||
return fileDescriptor_f84ccc98e143ed3e, []int{9}
|
||||
}
|
||||
|
||||
func (m *ListResponse) XXX_Unmarshal(b []byte) error {
|
||||
@@ -377,6 +415,7 @@ func (m *ListResponse) GetRecords() []*Record {
|
||||
|
||||
func init() {
|
||||
proto.RegisterType((*Record)(nil), "go.micro.store.Record")
|
||||
proto.RegisterType((*ReadOptions)(nil), "go.micro.store.ReadOptions")
|
||||
proto.RegisterType((*ReadRequest)(nil), "go.micro.store.ReadRequest")
|
||||
proto.RegisterType((*ReadResponse)(nil), "go.micro.store.ReadResponse")
|
||||
proto.RegisterType((*WriteRequest)(nil), "go.micro.store.WriteRequest")
|
||||
@@ -392,26 +431,28 @@ func init() {
|
||||
}
|
||||
|
||||
var fileDescriptor_f84ccc98e143ed3e = []byte{
|
||||
// 333 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x92, 0x4d, 0x4f, 0xc2, 0x40,
|
||||
0x10, 0x86, 0x59, 0x0a, 0x35, 0x0c, 0x1f, 0x92, 0x89, 0x21, 0x0d, 0x7e, 0xd5, 0x7a, 0xe9, 0xc5,
|
||||
0x42, 0xf0, 0x0f, 0x98, 0xf8, 0x11, 0x4d, 0x3c, 0xad, 0x07, 0xcf, 0x08, 0x13, 0xd2, 0x80, 0x2e,
|
||||
0xee, 0x16, 0x62, 0xff, 0x90, 0xbf, 0xd3, 0xec, 0x6e, 0xab, 0xc5, 0x42, 0x62, 0xbc, 0xcd, 0xee,
|
||||
0xbc, 0xf3, 0xec, 0xdb, 0x79, 0x0b, 0xd1, 0x6b, 0x3c, 0x91, 0x62, 0x30, 0x13, 0x17, 0xb6, 0x50,
|
||||
0x89, 0x90, 0x34, 0x50, 0x24, 0xd7, 0xf1, 0x84, 0x06, 0x4b, 0x29, 0x92, 0xec, 0x2e, 0x32, 0x35,
|
||||
0x76, 0x66, 0xc2, 0x8e, 0x44, 0xe6, 0x36, 0xb8, 0x07, 0x97, 0xd3, 0x44, 0xc8, 0x29, 0x76, 0xc1,
|
||||
0x99, 0x53, 0xea, 0x31, 0x9f, 0x85, 0x0d, 0xae, 0x4b, 0x3c, 0x80, 0xfa, 0x7a, 0xbc, 0x58, 0x91,
|
||||
0x57, 0xf5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b1, 0x24, 0xdd, 0xc8, 0xa3, 0x7f, 0xb2, 0xab, 0x9d, 0xa3, 0x5e, 0x5c, 0xf3, 0x6f, 0x5f, 0x7e,
|
||||
0x05, 0x00, 0x00, 0xff, 0xff, 0x30, 0x48, 0x25, 0x2d, 0x0d, 0x03, 0x00, 0x00,
|
||||
// 364 bytes of a gzipped FileDescriptorProto
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x4d, 0x4b, 0xc3, 0x40,
|
||||
0x10, 0x6d, 0x9a, 0x36, 0xd5, 0x49, 0x5b, 0xcb, 0x22, 0x25, 0xd4, 0x0f, 0xe2, 0x82, 0x90, 0x8b,
|
||||
0x69, 0xa9, 0x78, 0x15, 0xc1, 0x0f, 0x14, 0x04, 0x61, 0x05, 0x3d, 0xd7, 0x76, 0x2c, 0xc1, 0xda,
|
||||
0x8d, 0xbb, 0x69, 0x69, 0xff, 0x90, 0xbf, 0x53, 0xb2, 0xbb, 0xd1, 0x94, 0x34, 0x17, 0x6f, 0x33,
|
||||
0xfb, 0xde, 0xbc, 0x99, 0x79, 0xc3, 0x42, 0xf8, 0x19, 0x8d, 0x05, 0xef, 0x4f, 0xf9, 0x99, 0x0e,
|
||||
0x64, 0xc2, 0x05, 0xf6, 0x25, 0x8a, 0x65, 0x34, 0xc6, 0x7e, 0x2c, 0x78, 0x62, 0xde, 0x42, 0x15,
|
||||
0x93, 0xf6, 0x94, 0xeb, 0x92, 0x50, 0xbd, 0xd2, 0x7b, 0x70, 0x18, 0x8e, 0xb9, 0x98, 0x90, 0x0e,
|
||||
0xd8, 0x1f, 0xb8, 0xf6, 0x2c, 0xdf, 0x0a, 0x76, 0x59, 0x1a, 0x92, 0x7d, 0xa8, 0x2f, 0x47, 0xb3,
|
||||
0x05, 0x7a, 0x55, 0xdf, 0x0a, 0x9a, 0x4c, 0x27, 0xa4, 0x0b, 0x0e, 0xae, 0xe2, 0x48, 0xac, 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, 0x3b, 0xa8, 0x2b,
|
||||
0xb3, 0x48, 0x81, 0x98, 0xbf, 0x41, 0xef, 0xa8, 0x04, 0xfd, 0xd5, 0x79, 0x00, 0x47, 0x1b, 0x48,
|
||||
0x0a, 0xd4, 0x0d, 0xef, 0x7b, 0xc7, 0x65, 0x70, 0x26, 0xf5, 0xe6, 0xa8, 0x1f, 0x72, 0xfe, 0x13,
|
||||
0x00, 0x00, 0xff, 0xff, 0xf9, 0x20, 0x54, 0x71, 0x53, 0x03, 0x00, 0x00,
|
||||
}
|
||||
|
@@ -18,8 +18,13 @@ message Record {
|
||||
int64 expiry = 3;
|
||||
}
|
||||
|
||||
message ReadOptions {
|
||||
bool prefix = 1;
|
||||
}
|
||||
|
||||
message ReadRequest {
|
||||
repeated string keys = 1;
|
||||
string key = 1;
|
||||
ReadOptions options = 2;
|
||||
}
|
||||
|
||||
message ReadResponse {
|
||||
@@ -27,21 +32,18 @@ message ReadResponse {
|
||||
}
|
||||
|
||||
message WriteRequest {
|
||||
repeated Record records = 2;
|
||||
Record record = 1;
|
||||
}
|
||||
|
||||
message WriteResponse {}
|
||||
|
||||
message DeleteRequest {
|
||||
repeated string keys = 1;
|
||||
string key = 1;
|
||||
}
|
||||
|
||||
message DeleteResponse {}
|
||||
|
||||
message ListRequest {
|
||||
// optional key
|
||||
string key = 1;
|
||||
}
|
||||
message ListRequest {}
|
||||
|
||||
message ListResponse {
|
||||
repeated Record records = 1;
|
||||
|
@@ -73,6 +73,7 @@ func (s *serviceStore) List() ([]*store.Record, error) {
|
||||
if err != nil {
|
||||
return records, err
|
||||
}
|
||||
|
||||
for _, record := range rsp.Records {
|
||||
records = append(records, &store.Record{
|
||||
Key: record.Key,
|
||||
@@ -86,15 +87,24 @@ func (s *serviceStore) List() ([]*store.Record, error) {
|
||||
}
|
||||
|
||||
// Read a record with key
|
||||
func (s *serviceStore) Read(keys ...string) ([]*store.Record, error) {
|
||||
func (s *serviceStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
|
||||
var options store.ReadOptions
|
||||
for _, o := range opts {
|
||||
o(&options)
|
||||
}
|
||||
|
||||
rsp, err := s.Client.Read(s.Context(), &pb.ReadRequest{
|
||||
Keys: keys,
|
||||
Key: key,
|
||||
Options: &pb.ReadOptions{
|
||||
Prefix: options.Prefix,
|
||||
},
|
||||
}, client.WithAddress(s.Nodes...))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
records := make([]*store.Record, 0, len(rsp.Records))
|
||||
|
||||
for _, val := range rsp.Records {
|
||||
records = append(records, &store.Record{
|
||||
Key: val.Key,
|
||||
@@ -102,32 +112,27 @@ func (s *serviceStore) Read(keys ...string) ([]*store.Record, error) {
|
||||
Expiry: time.Duration(val.Expiry) * time.Second,
|
||||
})
|
||||
}
|
||||
|
||||
return records, nil
|
||||
}
|
||||
|
||||
// Write a record
|
||||
func (s *serviceStore) Write(recs ...*store.Record) error {
|
||||
records := make([]*pb.Record, 0, len(recs))
|
||||
|
||||
for _, record := range recs {
|
||||
records = append(records, &pb.Record{
|
||||
func (s *serviceStore) Write(record *store.Record) error {
|
||||
_, err := s.Client.Write(s.Context(), &pb.WriteRequest{
|
||||
Record: &pb.Record{
|
||||
Key: record.Key,
|
||||
Value: record.Value,
|
||||
Expiry: int64(record.Expiry.Seconds()),
|
||||
})
|
||||
}
|
||||
|
||||
_, err := s.Client.Write(s.Context(), &pb.WriteRequest{
|
||||
Records: records,
|
||||
},
|
||||
}, client.WithAddress(s.Nodes...))
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Delete a record with key
|
||||
func (s *serviceStore) Delete(keys ...string) error {
|
||||
func (s *serviceStore) Delete(key string) error {
|
||||
_, err := s.Client.Delete(s.Context(), &pb.DeleteRequest{
|
||||
Keys: keys,
|
||||
Key: key,
|
||||
}, client.WithAddress(s.Nodes...))
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user