From d51582ce774d8197039200317874a9fd5490a028 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Wed, 19 May 2021 13:55:34 +0100 Subject: [PATCH] add the cache service (#112) --- cache/.gitignore | 2 + cache/Dockerfile | 3 + cache/Makefile | 29 ++ cache/README.md | 23 + cache/generate.go | 3 + cache/handler/cache.go | 90 ++++ cache/main.go | 25 + cache/micro.mu | 1 + cache/proto/cache.pb.go | 893 ++++++++++++++++++++++++++++++++++ cache/proto/cache.pb.micro.go | 161 ++++++ cache/proto/cache.proto | 89 ++++ 11 files changed, 1319 insertions(+) create mode 100644 cache/.gitignore create mode 100644 cache/Dockerfile create mode 100644 cache/Makefile create mode 100644 cache/README.md create mode 100644 cache/generate.go create mode 100644 cache/handler/cache.go create mode 100644 cache/main.go create mode 100644 cache/micro.mu create mode 100644 cache/proto/cache.pb.go create mode 100644 cache/proto/cache.pb.micro.go create mode 100644 cache/proto/cache.proto diff --git a/cache/.gitignore b/cache/.gitignore new file mode 100644 index 0000000..086645b --- /dev/null +++ b/cache/.gitignore @@ -0,0 +1,2 @@ + +cache diff --git a/cache/Dockerfile b/cache/Dockerfile new file mode 100644 index 0000000..792c159 --- /dev/null +++ b/cache/Dockerfile @@ -0,0 +1,3 @@ +FROM alpine +ADD cache /cache +ENTRYPOINT [ "/cache" ] diff --git a/cache/Makefile b/cache/Makefile new file mode 100644 index 0000000..9d01dff --- /dev/null +++ b/cache/Makefile @@ -0,0 +1,29 @@ + +GOPATH:=$(shell go env GOPATH) + +.PHONY: api +api: + protoc --openapi_out=. --proto_path=. proto/cache.proto + +.PHONY: init +init: + go get -u github.com/golang/protobuf/proto + go get -u github.com/golang/protobuf/protoc-gen-go + go get github.com/micro/micro/v3/cmd/protoc-gen-micro + go get github.com/micro/micro/v3/cmd/protoc-gen-openapi + +.PHONY: proto +proto: + protoc --proto_path=. --micro_out=. --go_out=:. proto/cache.proto + +.PHONY: build +build: + go build -o cache *.go + +.PHONY: test +test: + go test -v ./... -cover + +.PHONY: docker +docker: + docker build . -t cache:latest diff --git a/cache/README.md b/cache/README.md new file mode 100644 index 0000000..1e261bd --- /dev/null +++ b/cache/README.md @@ -0,0 +1,23 @@ +# Cache Service + +This is the Cache service + +Generated with + +``` +micro new cache +``` + +## Usage + +Generate the proto code + +``` +make proto +``` + +Run the service + +``` +micro run . +``` \ No newline at end of file diff --git a/cache/generate.go b/cache/generate.go new file mode 100644 index 0000000..7d9db91 --- /dev/null +++ b/cache/generate.go @@ -0,0 +1,3 @@ +package main + +//go:generate make proto diff --git a/cache/handler/cache.go b/cache/handler/cache.go new file mode 100644 index 0000000..dc2aaeb --- /dev/null +++ b/cache/handler/cache.go @@ -0,0 +1,90 @@ +package handler + +import ( + "context" + "time" + + "github.com/micro/micro/v3/service/errors" + pb "github.com/micro/services/cache/proto" + "github.com/micro/services/pkg/cache" +) + +type Cache struct{} + +func (c *Cache) Get(ctx context.Context, req *pb.GetRequest, rsp *pb.GetResponse) error { + if len(req.Key) == 0 { + return errors.BadRequest("cache.get", "missing key") + } + + item := new(pb.Item) + item.Key = req.Key + + if err := cache.Context(ctx).Get(req.Key, item.Value); err != nil { + return errors.InternalServerError("cache.get", err.Error()) + } + + return nil +} + +func (c *Cache) Set(ctx context.Context, req *pb.SetRequest, rsp *pb.SetResponse) error { + if len(req.Key) == 0 { + return errors.BadRequest("cache.get", "missing key") + } + + ttl := time.Time{} + + if req.Ttl > 0 { + ttl = time.Now().Add(time.Duration(req.Ttl) * time.Second) + } + + if err := cache.Context(ctx).Set(req.Key, req.Value, ttl); err != nil { + return errors.InternalServerError("cache.set", err.Error()) + } + + return nil +} + +func (c *Cache) Delete(ctx context.Context, req *pb.DeleteRequest, rsp *pb.DeleteResponse) error { + if len(req.Key) == 0 { + return errors.BadRequest("cache.get", "missing key") + } + if err := cache.Context(ctx).Delete(req.Key); err != nil { + return errors.InternalServerError("cache.delete", err.Error()) + } + return nil +} + +func (c *Cache) Increment(ctx context.Context, req *pb.IncrementRequest, rsp *pb.IncrementResponse) error { + if len(req.Key) == 0 { + return errors.BadRequest("cache.get", "missing key") + } + + // increment the value + v, err := cache.Context(ctx).Increment(req.Key, req.Value) + if err != nil { + return errors.InternalServerError("cache.increment", err.Error()) + } + + // set the response value + rsp.Key = req.Key + rsp.Value = v + + return nil +} + +func (c *Cache) Decrement(ctx context.Context, req *pb.DecrementRequest, rsp *pb.DecrementResponse) error { + if len(req.Key) == 0 { + return errors.BadRequest("cache.get", "missing key") + } + + v, err := cache.Context(ctx).Decrement(req.Key, req.Value) + if err != nil { + return errors.InternalServerError("cache.decrement", err.Error()) + } + + // set the response value + rsp.Key = req.Key + rsp.Value = v + + return nil +} diff --git a/cache/main.go b/cache/main.go new file mode 100644 index 0000000..dfd18d7 --- /dev/null +++ b/cache/main.go @@ -0,0 +1,25 @@ +package main + +import ( + "github.com/micro/services/cache/handler" + pb "github.com/micro/services/cache/proto" + + "github.com/micro/micro/v3/service" + "github.com/micro/micro/v3/service/logger" +) + +func main() { + // Create service + srv := service.New( + service.Name("cache"), + service.Version("latest"), + ) + + // Register handler + pb.RegisterCacheHandler(srv.Server(), new(handler.Cache)) + + // Run service + if err := srv.Run(); err != nil { + logger.Fatal(err) + } +} diff --git a/cache/micro.mu b/cache/micro.mu new file mode 100644 index 0000000..2de7ffd --- /dev/null +++ b/cache/micro.mu @@ -0,0 +1 @@ +service cache diff --git a/cache/proto/cache.pb.go b/cache/proto/cache.pb.go new file mode 100644 index 0000000..b861866 --- /dev/null +++ b/cache/proto/cache.pb.go @@ -0,0 +1,893 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.26.0 +// protoc v3.15.6 +// source: proto/cache.proto + +package cache + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type Item struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The value + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + // Time to live in seconds + Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"` +} + +func (x *Item) Reset() { + *x = Item{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Item) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Item) ProtoMessage() {} + +func (x *Item) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[0] + 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 Item.ProtoReflect.Descriptor instead. +func (*Item) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{0} +} + +func (x *Item) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *Item) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +func (x *Item) GetTtl() int64 { + if x != nil { + return x.Ttl + } + return 0 +} + +// Get an item from the cache by key +type GetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key to retrieve + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *GetRequest) Reset() { + *x = GetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetRequest) ProtoMessage() {} + +func (x *GetRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[1] + 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 GetRequest.ProtoReflect.Descriptor instead. +func (*GetRequest) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{1} +} + +func (x *GetRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +type GetResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The item in the cache + Item *Item `protobuf:"bytes,1,opt,name=item,proto3" json:"item,omitempty"` +} + +func (x *GetResponse) Reset() { + *x = GetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetResponse) ProtoMessage() {} + +func (x *GetResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[2] + 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 GetResponse.ProtoReflect.Descriptor instead. +func (*GetResponse) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{2} +} + +func (x *GetResponse) GetItem() *Item { + if x != nil { + return x.Item + } + return nil +} + +// Set an item in the cache +type SetRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key to update + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The value to set + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"` + // Time to live in seconds + Ttl int64 `protobuf:"varint,3,opt,name=ttl,proto3" json:"ttl,omitempty"` +} + +func (x *SetRequest) Reset() { + *x = SetRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetRequest) ProtoMessage() {} + +func (x *SetRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[3] + 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 SetRequest.ProtoReflect.Descriptor instead. +func (*SetRequest) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{3} +} + +func (x *SetRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *SetRequest) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +func (x *SetRequest) GetTtl() int64 { + if x != nil { + return x.Ttl + } + return 0 +} + +type SetResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Returns "ok" if successful + Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` +} + +func (x *SetResponse) Reset() { + *x = SetResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SetResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SetResponse) ProtoMessage() {} + +func (x *SetResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[4] + 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 SetResponse.ProtoReflect.Descriptor instead. +func (*SetResponse) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{4} +} + +func (x *SetResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +// Delete a value from the cache +type DeleteRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key to delete + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` +} + +func (x *DeleteRequest) Reset() { + *x = DeleteRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteRequest) ProtoMessage() {} + +func (x *DeleteRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[5] + 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 DeleteRequest.ProtoReflect.Descriptor instead. +func (*DeleteRequest) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{5} +} + +func (x *DeleteRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +type DeleteResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Returns "ok" if successful + Status string `protobuf:"bytes,1,opt,name=status,proto3" json:"status,omitempty"` +} + +func (x *DeleteResponse) Reset() { + *x = DeleteResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteResponse) ProtoMessage() {} + +func (x *DeleteResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[6] + 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 DeleteResponse.ProtoReflect.Descriptor instead. +func (*DeleteResponse) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{6} +} + +func (x *DeleteResponse) GetStatus() string { + if x != nil { + return x.Status + } + return "" +} + +// Increment a value (if its a number) +type IncrementRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key to increment + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The value to add + Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *IncrementRequest) Reset() { + *x = IncrementRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IncrementRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IncrementRequest) ProtoMessage() {} + +func (x *IncrementRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[7] + 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 IncrementRequest.ProtoReflect.Descriptor instead. +func (*IncrementRequest) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{7} +} + +func (x *IncrementRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *IncrementRequest) GetValue() int64 { + if x != nil { + return x.Value + } + return 0 +} + +type IncrementResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key incremented + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The result value + Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *IncrementResponse) Reset() { + *x = IncrementResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *IncrementResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*IncrementResponse) ProtoMessage() {} + +func (x *IncrementResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[8] + 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 IncrementResponse.ProtoReflect.Descriptor instead. +func (*IncrementResponse) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{8} +} + +func (x *IncrementResponse) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *IncrementResponse) GetValue() int64 { + if x != nil { + return x.Value + } + return 0 +} + +// Decrement a value (if its a number) +type DecrementRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key to decrement + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The delta value to decrement + Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *DecrementRequest) Reset() { + *x = DecrementRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DecrementRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DecrementRequest) ProtoMessage() {} + +func (x *DecrementRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_cache_proto_msgTypes[9] + 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 DecrementRequest.ProtoReflect.Descriptor instead. +func (*DecrementRequest) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{9} +} + +func (x *DecrementRequest) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *DecrementRequest) GetValue() int64 { + if x != nil { + return x.Value + } + return 0 +} + +type DecrementResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The key of the item + Key string `protobuf:"bytes,1,opt,name=key,proto3" json:"key,omitempty"` + // The result value of the item + Value int64 `protobuf:"varint,2,opt,name=value,proto3" json:"value,omitempty"` +} + +func (x *DecrementResponse) Reset() { + *x = DecrementResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_cache_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DecrementResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DecrementResponse) ProtoMessage() {} + +func (x *DecrementResponse) 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 DecrementResponse.ProtoReflect.Descriptor instead. +func (*DecrementResponse) Descriptor() ([]byte, []int) { + return file_proto_cache_proto_rawDescGZIP(), []int{10} +} + +func (x *DecrementResponse) GetKey() string { + if x != nil { + return x.Key + } + return "" +} + +func (x *DecrementResponse) GetValue() int64 { + if x != nil { + return x.Value + } + return 0 +} + +var File_proto_cache_proto protoreflect.FileDescriptor + +var file_proto_cache_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x63, 0x61, 0x63, 0x68, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x12, 0x05, 0x63, 0x61, 0x63, 0x68, 0x65, 0x22, 0x40, 0x0a, 0x04, 0x49, 0x74, + 0x65, 0x6d, 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, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x74, + 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x03, 0x74, 0x74, 0x6c, 0x22, 0x1e, 0x0a, 0x0a, + 0x47, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, + 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x2e, 0x0a, 0x0b, + 0x47, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1f, 0x0a, 0x04, 0x69, + 0x74, 0x65, 0x6d, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x63, 0x61, 0x63, 0x68, + 0x65, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x04, 0x69, 0x74, 0x65, 0x6d, 0x22, 0x46, 0x0a, 0x0a, + 0x53, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, + 0x75, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x74, 0x6c, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, + 0x03, 0x74, 0x74, 0x6c, 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x21, 0x0a, 0x0d, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x10, 0x0a, 0x03, + 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x22, 0x28, + 0x0a, 0x0e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x3a, 0x0a, 0x10, 0x49, 0x6e, 0x63, 0x72, + 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x22, 0x3b, 0x0a, 0x11, 0x49, 0x6e, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, + 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, 0x22, 0x3a, 0x0a, 0x10, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 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, 0x22, 0x3b, 0x0a, + 0x11, 0x44, 0x65, 0x63, 0x72, 0x65, 0x6d, 0x65, 0x6e, 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, +} + +var ( + file_proto_cache_proto_rawDescOnce sync.Once + file_proto_cache_proto_rawDescData = file_proto_cache_proto_rawDesc +) + +func file_proto_cache_proto_rawDescGZIP() []byte { + file_proto_cache_proto_rawDescOnce.Do(func() { + file_proto_cache_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_cache_proto_rawDescData) + }) + return file_proto_cache_proto_rawDescData +} + +var file_proto_cache_proto_msgTypes = make([]protoimpl.MessageInfo, 11) +var file_proto_cache_proto_goTypes = []interface{}{ + (*Item)(nil), // 0: cache.Item + (*GetRequest)(nil), // 1: cache.GetRequest + (*GetResponse)(nil), // 2: cache.GetResponse + (*SetRequest)(nil), // 3: cache.SetRequest + (*SetResponse)(nil), // 4: cache.SetResponse + (*DeleteRequest)(nil), // 5: cache.DeleteRequest + (*DeleteResponse)(nil), // 6: cache.DeleteResponse + (*IncrementRequest)(nil), // 7: cache.IncrementRequest + (*IncrementResponse)(nil), // 8: cache.IncrementResponse + (*DecrementRequest)(nil), // 9: cache.DecrementRequest + (*DecrementResponse)(nil), // 10: cache.DecrementResponse +} +var file_proto_cache_proto_depIdxs = []int32{ + 0, // 0: cache.GetResponse.item:type_name -> cache.Item + 1, // 1: cache.Cache.Get:input_type -> cache.GetRequest + 3, // 2: cache.Cache.Set:input_type -> cache.SetRequest + 5, // 3: cache.Cache.Delete:input_type -> cache.DeleteRequest + 7, // 4: cache.Cache.Increment:input_type -> cache.IncrementRequest + 9, // 5: cache.Cache.Decrement:input_type -> cache.DecrementRequest + 2, // 6: cache.Cache.Get:output_type -> cache.GetResponse + 4, // 7: cache.Cache.Set:output_type -> cache.SetResponse + 6, // 8: cache.Cache.Delete:output_type -> cache.DeleteResponse + 8, // 9: cache.Cache.Increment:output_type -> cache.IncrementResponse + 10, // 10: cache.Cache.Decrement:output_type -> cache.DecrementResponse + 6, // [6:11] is the sub-list for method output_type + 1, // [1:6] is the sub-list for method input_type + 1, // [1:1] is the sub-list for extension type_name + 1, // [1:1] is the sub-list for extension extendee + 0, // [0:1] is the sub-list for field type_name +} + +func init() { file_proto_cache_proto_init() } +func file_proto_cache_proto_init() { + if File_proto_cache_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_cache_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Item); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SetResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IncrementRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*IncrementResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DecrementRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_cache_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DecrementResponse); 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{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_cache_proto_rawDesc, + NumEnums: 0, + NumMessages: 11, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_cache_proto_goTypes, + DependencyIndexes: file_proto_cache_proto_depIdxs, + MessageInfos: file_proto_cache_proto_msgTypes, + }.Build() + File_proto_cache_proto = out.File + file_proto_cache_proto_rawDesc = nil + file_proto_cache_proto_goTypes = nil + file_proto_cache_proto_depIdxs = nil +} diff --git a/cache/proto/cache.pb.micro.go b/cache/proto/cache.pb.micro.go new file mode 100644 index 0000000..18cbade --- /dev/null +++ b/cache/proto/cache.pb.micro.go @@ -0,0 +1,161 @@ +// Code generated by protoc-gen-micro. DO NOT EDIT. +// source: proto/cache.proto + +package cache + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + math "math" +) + +import ( + context "context" + api "github.com/micro/micro/v3/service/api" + client "github.com/micro/micro/v3/service/client" + server "github.com/micro/micro/v3/service/server" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package + +// Reference imports to suppress errors if they are not otherwise used. +var _ api.Endpoint +var _ context.Context +var _ client.Option +var _ server.Option + +// Api Endpoints for Cache service + +func NewCacheEndpoints() []*api.Endpoint { + return []*api.Endpoint{} +} + +// Client API for Cache service + +type CacheService interface { + Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*GetResponse, error) + Set(ctx context.Context, in *SetRequest, opts ...client.CallOption) (*SetResponse, error) + Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) + Increment(ctx context.Context, in *IncrementRequest, opts ...client.CallOption) (*IncrementResponse, error) + Decrement(ctx context.Context, in *DecrementRequest, opts ...client.CallOption) (*DecrementResponse, error) +} + +type cacheService struct { + c client.Client + name string +} + +func NewCacheService(name string, c client.Client) CacheService { + return &cacheService{ + c: c, + name: name, + } +} + +func (c *cacheService) Get(ctx context.Context, in *GetRequest, opts ...client.CallOption) (*GetResponse, error) { + req := c.c.NewRequest(c.name, "Cache.Get", in) + out := new(GetResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheService) Set(ctx context.Context, in *SetRequest, opts ...client.CallOption) (*SetResponse, error) { + req := c.c.NewRequest(c.name, "Cache.Set", in) + out := new(SetResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheService) Delete(ctx context.Context, in *DeleteRequest, opts ...client.CallOption) (*DeleteResponse, error) { + req := c.c.NewRequest(c.name, "Cache.Delete", in) + out := new(DeleteResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheService) Increment(ctx context.Context, in *IncrementRequest, opts ...client.CallOption) (*IncrementResponse, error) { + req := c.c.NewRequest(c.name, "Cache.Increment", in) + out := new(IncrementResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheService) Decrement(ctx context.Context, in *DecrementRequest, opts ...client.CallOption) (*DecrementResponse, error) { + req := c.c.NewRequest(c.name, "Cache.Decrement", in) + out := new(DecrementResponse) + err := c.c.Call(ctx, req, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Cache service + +type CacheHandler interface { + Get(context.Context, *GetRequest, *GetResponse) error + Set(context.Context, *SetRequest, *SetResponse) error + Delete(context.Context, *DeleteRequest, *DeleteResponse) error + Increment(context.Context, *IncrementRequest, *IncrementResponse) error + Decrement(context.Context, *DecrementRequest, *DecrementResponse) error +} + +func RegisterCacheHandler(s server.Server, hdlr CacheHandler, opts ...server.HandlerOption) error { + type cache interface { + Get(ctx context.Context, in *GetRequest, out *GetResponse) error + Set(ctx context.Context, in *SetRequest, out *SetResponse) error + Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error + Increment(ctx context.Context, in *IncrementRequest, out *IncrementResponse) error + Decrement(ctx context.Context, in *DecrementRequest, out *DecrementResponse) error + } + type Cache struct { + cache + } + h := &cacheHandler{hdlr} + return s.Handle(s.NewHandler(&Cache{h}, opts...)) +} + +type cacheHandler struct { + CacheHandler +} + +func (h *cacheHandler) Get(ctx context.Context, in *GetRequest, out *GetResponse) error { + return h.CacheHandler.Get(ctx, in, out) +} + +func (h *cacheHandler) Set(ctx context.Context, in *SetRequest, out *SetResponse) error { + return h.CacheHandler.Set(ctx, in, out) +} + +func (h *cacheHandler) Delete(ctx context.Context, in *DeleteRequest, out *DeleteResponse) error { + return h.CacheHandler.Delete(ctx, in, out) +} + +func (h *cacheHandler) Increment(ctx context.Context, in *IncrementRequest, out *IncrementResponse) error { + return h.CacheHandler.Increment(ctx, in, out) +} + +func (h *cacheHandler) Decrement(ctx context.Context, in *DecrementRequest, out *DecrementResponse) error { + return h.CacheHandler.Decrement(ctx, in, out) +} diff --git a/cache/proto/cache.proto b/cache/proto/cache.proto new file mode 100644 index 0000000..adaf33e --- /dev/null +++ b/cache/proto/cache.proto @@ -0,0 +1,89 @@ +syntax = "proto3"; + +package cache; + +option go_package = "./proto;cache"; + +service Cache { + rpc Get(GetRequest) returns (GetResponse) {} + rpc Set(SetRequest) returns (SetResponse) {} + rpc Delete(DeleteRequest) returns (DeleteResponse) {} + rpc Increment(IncrementRequest) returns (IncrementResponse) {} + rpc Decrement(DecrementRequest) returns (DecrementResponse) {} +} + +message Item { + // The key + string key = 1; + // The value + string value = 2; + // Time to live in seconds + int64 ttl = 3; +} + +// Get an item from the cache by key +message GetRequest { + // The key to retrieve + string key = 1; +} + +message GetResponse { + // The item in the cache + Item item = 1; +} + +// Set an item in the cache +message SetRequest { + // The key to update + string key = 1; + // The value to set + string value = 2; + // Time to live in seconds + int64 ttl = 3; +} + +message SetResponse { + // Returns "ok" if successful + string status = 1; +} + +// Delete a value from the cache +message DeleteRequest { + // The key to delete + string key = 1; +} + +message DeleteResponse { + // Returns "ok" if successful + string status = 1; +} + +// Increment a value (if its a number) +message IncrementRequest { + // The key to increment + string key = 1; + // The value to add + int64 value = 2; +} + +message IncrementResponse { + // The key incremented + string key = 1; + // The result value + int64 value = 2; +} + +// Decrement a value (if its a number) +message DecrementRequest { + // The key to decrement + string key = 1; + // The delta value to decrement + int64 value = 2; +} + +message DecrementResponse { + // The key of the item + string key = 1; + // The result value of the item + int64 value = 2; +}