Browse Source

设置KEY增加过期时间

master
guzeng 3 years ago
parent
commit
8ff17c2b16
4 changed files with 21 additions and 13 deletions
  1. +3
    -3
      redis.pb.go
  2. +1
    -1
      redis.proto
  3. +3
    -3
      string.go
  4. +14
    -6
      string_test.go

+ 3
- 3
redis.pb.go View File

@ -56,7 +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"`
Ttl *string `protobuf:"bytes,3,opt,name=ttl" json:"ttl,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
@ -78,11 +78,11 @@ func (m *SetRequest) GetValue() string {
return ""
}
func (m *SetRequest) GetTtl() uint64 {
func (m *SetRequest) GetTtl() string {
if m != nil && m.Ttl != nil {
return *m.Ttl
}
return 0
return ""
}
type DelRequest struct {


+ 1
- 1
redis.proto View File

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


+ 3
- 3
string.go View File

@ -30,7 +30,7 @@ func GetString(key string, url ...string) (string, error) {
}
//设置
func Set(key, value string, ttl uint64, url ...string) (uint64, error) {
func Set(key, value string, ttl string, url ...string) (uint64, error) {
conn, _, err := Conn(url...)
@ -39,7 +39,7 @@ func Set(key, value string, ttl uint64, url ...string) (uint64, error) {
}
defer conn.Close()
req := &SetRequest{proto.String(key), proto.String(value), proto.Uint64(ttl), nil}
req := &SetRequest{proto.String(key), proto.String(value), proto.String(ttl), nil}
res := &SetResponse{}
@ -53,7 +53,7 @@ func Set(key, value string, ttl uint64, url ...string) (uint64, error) {
}
//设置
func Del(key, value string, url ...string) (uint64, error) {
func Del(key string, url ...string) (uint64, error) {
conn, _, err := Conn(url...)


+ 14
- 6
string_test.go View File

@ -5,18 +5,26 @@ import (
// "time"
)
func Test_Get(t *testing.T) {
// func Test_Get(t *testing.T) {
reply, err := GetString("siteListCache")
// reply, err := GetString("siteListCache")
t.Log(reply)
t.Log(err)
}
// t.Log(reply)
// t.Log(err)
// }
func Test_Set(t *testing.T) {
c, err := Set("test", 1111, 7200)
c, err := Set("test", "1111", 7200)
t.Log(c)
t.Log(err)
}
// func Test_Del(t *testing.T) {
// c, err := Del("test")
// t.Log(c)
// t.Log(err)
// }

Loading…
Cancel
Save