add list keys to cache (#352)

* add list keys to cache

* add list keys example
This commit is contained in:
Asim Aslam
2022-01-14 17:38:47 +00:00
committed by GitHub
parent f96ace75c2
commit 6a7d7db044
6 changed files with 250 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc-gen-go v1.27.1
// protoc v3.15.6
// source: proto/cache.proto
@@ -20,7 +20,7 @@ const (
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
// Get an item from the cache by key
// Get an item from the cache by key. If key is not found, an empty response is returned.
type GetRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -135,7 +135,7 @@ func (x *GetResponse) GetTtl() int64 {
return 0
}
// Set an item in the cache
// Set an item in the cache. Overwrites any existing value already set.
type SetRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -250,7 +250,7 @@ func (x *SetResponse) GetStatus() string {
return ""
}
// Delete a value from the cache
// Delete a value from the cache. If key not found a success response is returned.
type DeleteRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -347,7 +347,7 @@ func (x *DeleteResponse) GetStatus() string {
return ""
}
// Increment a value (if its a number)
// Increment a value (if it's a number). If key not found it is equivalent to set.
type IncrementRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -355,7 +355,7 @@ type IncrementRequest struct {
// The key to increment
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// The value to add
// The amount to increment the value by
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
}
@@ -412,7 +412,7 @@ type IncrementResponse struct {
// The key incremented
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// The result value
// The new value
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
}
@@ -462,7 +462,7 @@ func (x *IncrementResponse) GetValue() int64 {
return 0
}
// Decrement a value (if its a number)
// Decrement a value (if it's a number). If key not found it is equivalent to set.
type DecrementRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@@ -470,7 +470,7 @@ type DecrementRequest struct {
// The key to decrement
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// The delta value to decrement
// The amount to decrement the value by
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
}
@@ -525,9 +525,9 @@ type DecrementResponse struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
// The key of the item
// The key decremented
Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"`
// The result value of the item
// The new value
Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"`
}
@@ -577,6 +577,92 @@ func (x *DecrementResponse) GetValue() int64 {
return 0
}
// List all the available keys
type ListKeysRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *ListKeysRequest) Reset() {
*x = ListKeysRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_cache_proto_msgTypes[10]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListKeysRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListKeysRequest) ProtoMessage() {}
func (x *ListKeysRequest) ProtoReflect() protoreflect.Message {
mi := &file_proto_cache_proto_msgTypes[10]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListKeysRequest.ProtoReflect.Descriptor instead.
func (*ListKeysRequest) Descriptor() ([]byte, []int) {
return file_proto_cache_proto_rawDescGZIP(), []int{10}
}
type ListKeysResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Keys []string `protobuf:"bytes,1,rep,name=keys,proto3" json:"keys,omitempty"`
}
func (x *ListKeysResponse) Reset() {
*x = ListKeysResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_proto_cache_proto_msgTypes[11]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *ListKeysResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*ListKeysResponse) ProtoMessage() {}
func (x *ListKeysResponse) ProtoReflect() protoreflect.Message {
mi := &file_proto_cache_proto_msgTypes[11]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use ListKeysResponse.ProtoReflect.Descriptor instead.
func (*ListKeysResponse) Descriptor() ([]byte, []int) {
return file_proto_cache_proto_rawDescGZIP(), []int{11}
}
func (x *ListKeysResponse) GetKeys() []string {
if x != nil {
return x.Keys
}
return nil
}
var File_proto_cache_proto protoreflect.FileDescriptor
var file_proto_cache_proto_rawDesc = []byte{
@@ -615,27 +701,34 @@ var file_proto_cache_proto_rawDesc = []byte{
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79,
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x76,
0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75,
0x65, 0x32, 0xa4, 0x02, 0x0a, 0x05, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x2e, 0x0a, 0x03, 0x47,
0x65, 0x74, 0x12, 0x11, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x47, 0x65,
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x03, 0x53,
0x65, 0x74, 0x12, 0x11, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x12, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x53, 0x65,
0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x44, 0x65,
0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x63, 0x61,
0x63, 0x68, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e,
0x74, 0x12, 0x17, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d,
0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x61, 0x63,
0x68, 0x65, 0x2e, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d,
0x65, 0x6e, 0x74, 0x12, 0x17, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x44, 0x65, 0x63, 0x72,
0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63,
0x61, 0x63, 0x68, 0x65, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72,
0x6f, 0x74, 0x6f, 0x3b, 0x63, 0x61, 0x63, 0x68, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x33,
0x65, 0x22, 0x11, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x22, 0x26, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6b, 0x65, 0x79, 0x73,
0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x6b, 0x65, 0x79, 0x73, 0x32, 0xe3, 0x02, 0x0a,
0x05, 0x43, 0x61, 0x63, 0x68, 0x65, 0x12, 0x2e, 0x0a, 0x03, 0x47, 0x65, 0x74, 0x12, 0x11, 0x2e,
0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x12, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x2e, 0x0a, 0x03, 0x53, 0x65, 0x74, 0x12, 0x11, 0x2e,
0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
0x1a, 0x12, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70,
0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x37, 0x0a, 0x06, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65,
0x12, 0x14, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52,
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x44,
0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12,
0x40, 0x0a, 0x09, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x17, 0x2e, 0x63,
0x61, 0x63, 0x68, 0x65, 0x2e, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x49, 0x6e,
0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x12, 0x40, 0x0a, 0x09, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x12, 0x17,
0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e,
0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x08, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x12,
0x16, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73,
0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e,
0x4c, 0x69, 0x73, 0x74, 0x4b, 0x65, 0x79, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x22, 0x00, 0x42, 0x0f, 0x5a, 0x0d, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x63, 0x61,
0x63, 0x68, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@@ -650,7 +743,7 @@ func file_proto_cache_proto_rawDescGZIP() []byte {
return file_proto_cache_proto_rawDescData
}
var file_proto_cache_proto_msgTypes = make([]protoimpl.MessageInfo, 10)
var file_proto_cache_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
var file_proto_cache_proto_goTypes = []interface{}{
(*GetRequest)(nil), // 0: cache.GetRequest
(*GetResponse)(nil), // 1: cache.GetResponse
@@ -662,23 +755,27 @@ var file_proto_cache_proto_goTypes = []interface{}{
(*IncrementResponse)(nil), // 7: cache.IncrementResponse
(*DecrementRequest)(nil), // 8: cache.DecrementRequest
(*DecrementResponse)(nil), // 9: cache.DecrementResponse
(*ListKeysRequest)(nil), // 10: cache.ListKeysRequest
(*ListKeysResponse)(nil), // 11: cache.ListKeysResponse
}
var file_proto_cache_proto_depIdxs = []int32{
0, // 0: cache.Cache.Get:input_type -> cache.GetRequest
2, // 1: cache.Cache.Set:input_type -> cache.SetRequest
4, // 2: cache.Cache.Delete:input_type -> cache.DeleteRequest
6, // 3: cache.Cache.Increment:input_type -> cache.IncrementRequest
8, // 4: cache.Cache.Decrement:input_type -> cache.DecrementRequest
1, // 5: cache.Cache.Get:output_type -> cache.GetResponse
3, // 6: cache.Cache.Set:output_type -> cache.SetResponse
5, // 7: cache.Cache.Delete:output_type -> cache.DeleteResponse
7, // 8: cache.Cache.Increment:output_type -> cache.IncrementResponse
9, // 9: cache.Cache.Decrement:output_type -> cache.DecrementResponse
5, // [5:10] is the sub-list for method output_type
0, // [0:5] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
0, // 0: cache.Cache.Get:input_type -> cache.GetRequest
2, // 1: cache.Cache.Set:input_type -> cache.SetRequest
4, // 2: cache.Cache.Delete:input_type -> cache.DeleteRequest
6, // 3: cache.Cache.Increment:input_type -> cache.IncrementRequest
8, // 4: cache.Cache.Decrement:input_type -> cache.DecrementRequest
10, // 5: cache.Cache.ListKeys:input_type -> cache.ListKeysRequest
1, // 6: cache.Cache.Get:output_type -> cache.GetResponse
3, // 7: cache.Cache.Set:output_type -> cache.SetResponse
5, // 8: cache.Cache.Delete:output_type -> cache.DeleteResponse
7, // 9: cache.Cache.Increment:output_type -> cache.IncrementResponse
9, // 10: cache.Cache.Decrement:output_type -> cache.DecrementResponse
11, // 11: cache.Cache.ListKeys:output_type -> cache.ListKeysResponse
6, // [6:12] is the sub-list for method output_type
0, // [0:6] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_proto_cache_proto_init() }
@@ -807,6 +904,30 @@ func file_proto_cache_proto_init() {
return nil
}
}
file_proto_cache_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListKeysRequest); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_proto_cache_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListKeysResponse); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@@ -814,7 +935,7 @@ func file_proto_cache_proto_init() {
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_proto_cache_proto_rawDesc,
NumEnums: 0,
NumMessages: 10,
NumMessages: 12,
NumExtensions: 0,
NumServices: 1,
},