diff --git a/go.mod b/go.mod index 4f98d6d..df3f1ed 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +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 + git.tetele.net/tgo/conf v0.25.0 + github.com/chai2010/protorpc v1.0.0 + github.com/golang/protobuf v1.5.2 ) diff --git a/hash.go b/hash.go index fe54af0..04126cb 100644 --- a/hash.go +++ b/hash.go @@ -113,3 +113,27 @@ func HGetAll(key string, url ...string) ([]map[string]string, error) { } 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 +} diff --git a/string.go b/string.go index 4124caf..fad0325 100644 --- a/string.go +++ b/string.go @@ -74,3 +74,24 @@ func Del(key string, url ...string) (int64, error) { 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 +}