From b5a2c62663c3db2d4665c52c076a52011d8674ab Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Sat, 10 Jul 2021 10:58:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E9=94=AE?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 +++--- hash.go | 24 ++++++++++++++++++++++++ string.go | 21 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 3 deletions(-) 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 +}