Browse Source

添加查询键是否存在方法

master v0.3.2
listen 3 years ago
parent
commit
b5a2c62663
3 changed files with 48 additions and 3 deletions
  1. +3
    -3
      go.mod
  2. +24
    -0
      hash.go
  3. +21
    -0
      string.go

+ 3
- 3
go.mod View File

@ -3,7 +3,7 @@ module git.tetele.net/tgo/redisrpc
go 1.14 go 1.14
require ( 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
git.tetele.net/tgo/conf v0.25.0
github.com/chai2010/protorpc v1.0.0
github.com/golang/protobuf v1.5.2
) )

+ 24
- 0
hash.go View File

@ -113,3 +113,27 @@ func HGetAll(key string, url ...string) ([]map[string]string, error) {
} }
return list, nil return list, nil
} }
/**
* hash键是否存在
*/
func HExists(key string, field string, url ...string)(int64,error){
conn, _, err := Conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
req := &HGetRequest{proto.String(key), proto.String(field), nil}
res := &DelResponse{}
err = conn.HExists(req, res)
if err != nil {
return 0, err
}
return res.GetRet(), nil
}

+ 21
- 0
string.go View File

@ -74,3 +74,24 @@ func Del(key string, url ...string) (int64, error) {
return res.GetRet(), nil return res.GetRet(), nil
} }
func Exists(key string, url ...string)(int64, error){
conn, _, err := Conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
req := &GetRequest{proto.String(key), nil}
res := &DelResponse{}
err = conn.Exists(req, res)
if err != nil {
return 0, err
}
return res.GetRet(), nil
}

Loading…
Cancel
Save