Browse Source

设置KEY增加过期时间

master
guzeng 3 years ago
parent
commit
e4059e753a
6 changed files with 20 additions and 8 deletions
  1. +1
    -0
      go.mod
  2. +2
    -0
      go.sum
  3. +8
    -0
      redis.pb.go
  4. +1
    -0
      redis.proto
  5. +2
    -2
      string.go
  6. +6
    -6
      string_test.go

+ 1
- 0
go.mod View File

@ -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
)

+ 2
- 0
go.sum View File

@ -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=


+ 8
- 0
redis.pb.go View File

@ -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:"-"`


+ 1
- 0
redis.proto View File

@ -9,6 +9,7 @@ message GetRequest {
message SetRequest {
string key = 1;
string value = 2;
uint64 ttl = 3;
}
message DelRequest {
string key = 1;


+ 2
- 2
string.go View File

@ -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{}


+ 6
- 6
string_test.go View File

@ -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)
// }
}

Loading…
Cancel
Save