From e4059e753a7395529b0c053d182c31c061ad4c8b Mon Sep 17 00:00:00 2001 From: guzeng Date: Fri, 21 May 2021 10:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E7=BD=AEKEY=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 1 + go.sum | 2 ++ redis.pb.go | 8 ++++++++ redis.proto | 1 + string.go | 4 ++-- string_test.go | 12 ++++++------ 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b3f3d50..4f98d6d 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module git.tetele.net/tgo/redisrpc go 1.14 require ( + git.tetele.net/tgo/conf v0.25.0 // indirect github.com/chai2010/protorpc v1.0.0 // indirect github.com/golang/protobuf v1.5.2 // indirect ) diff --git a/go.sum b/go.sum index 35feb65..778c639 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +git.tetele.net/tgo/conf v0.25.0 h1:fopDch45xw/di5fLvvzwltFiGiXrilMobZwQNO678Wo= +git.tetele.net/tgo/conf v0.25.0/go.mod h1:DogEBvxG2fGdukpoobTVFE2b4Fd5OTE9FJ3Xetyn47E= github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo= github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54= github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= diff --git a/redis.pb.go b/redis.pb.go index 5da4bef..a2cf5af 100644 --- a/redis.pb.go +++ b/redis.pb.go @@ -56,6 +56,7 @@ func (m *GetRequest) GetKey() string { type SetRequest struct { Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` Value *string `protobuf:"bytes,2,opt,name=value" json:"value,omitempty"` + Ttl *uint64 `protobuf:"varint,3,opt,name=ttl" json:"ttl,omitempty"` XXX_unrecognized []byte `json:"-"` } @@ -77,6 +78,13 @@ func (m *SetRequest) GetValue() string { return "" } +func (m *SetRequest) GetTtl() uint64 { + if m != nil && m.Ttl != nil { + return *m.Ttl + } + return 0 +} + type DelRequest struct { Key *string `protobuf:"bytes,1,opt,name=key" json:"key,omitempty"` XXX_unrecognized []byte `json:"-"` diff --git a/redis.proto b/redis.proto index 97150bd..7948c1d 100644 --- a/redis.proto +++ b/redis.proto @@ -9,6 +9,7 @@ message GetRequest { message SetRequest { string key = 1; string value = 2; + uint64 ttl = 3; } message DelRequest { string key = 1; diff --git a/string.go b/string.go index 93bbe03..1179504 100644 --- a/string.go +++ b/string.go @@ -30,7 +30,7 @@ func GetString(key string, url ...string) (string, error) { } //设置 -func Set(key, value string, url ...string) (uint64, error) { +func Set(key, value string, ttl uint64, url ...string) (uint64, error) { conn, _, err := Conn(url...) @@ -39,7 +39,7 @@ func Set(key, value string, url ...string) (uint64, error) { } defer conn.Close() - req := &SetRequest{proto.String(key), proto.String(value), nil} + req := &SetRequest{proto.String(key), proto.String(value),proto.Uint64(ttl) nil} res := &SetResponse{} diff --git a/string_test.go b/string_test.go index 16a7952..2635db7 100644 --- a/string_test.go +++ b/string_test.go @@ -7,16 +7,16 @@ import ( func Test_Get(t *testing.T) { - reply, err := Get("siteListCache") + reply, err := GetString("siteListCache") t.Log(reply) t.Log(err) } -// func Test_Set(t *testing.T) { +func Test_Set(t *testing.T) { -// c, err := Set("test", 1111, 7200) -// t.Log(c) -// t.Log(err) + c, err := Set("test", 1111, 7200) + t.Log(c) + t.Log(err) -// } +}