From 792d0213074deecdb6c82d3dafd506e3ddd6601a Mon Sep 17 00:00:00 2001 From: listen <494177603@qq.com> Date: Tue, 7 Dec 2021 14:33:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0scard=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- num_test.go | 7 ------- set.go | 26 ++++++++++++++++++++++++++ set_test.go | 7 +++++++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/num_test.go b/num_test.go index fe6938f..be92925 100644 --- a/num_test.go +++ b/num_test.go @@ -5,13 +5,6 @@ import ( // "time" ) -func Test_Incrby(t *testing.T) { - - c, err := Incrby("test_incrby", 10) - t.Log(c) - t.Log(err) - -} func Test_Decrby(t *testing.T) { diff --git a/set.go b/set.go index 6c86056..f85a481 100644 --- a/set.go +++ b/set.go @@ -74,3 +74,29 @@ func SIsmember(key string, field string, url ...string) (int64, error) { return res.GetRet(), nil } + + +/** + * 集合成员数 + */ +func SCard(key string,url ...string) (int64, error) { + + conn, _, err := Conn(url...) + + if err != nil { + return 0, err + } + defer conn.Close() + + req := &SMembersRequest{proto.String(key),nil} + + res := &SSetResponse{} + + err = conn.SCard(req, res) + + if err != nil { + return 0, err + } + + return res.GetRet(), nil +} \ No newline at end of file diff --git a/set_test.go b/set_test.go index be10b2f..a3b580e 100644 --- a/set_test.go +++ b/set_test.go @@ -19,3 +19,10 @@ func Test_SAdd(t *testing.T) { t.Log(err) } + +func Test_SCard(t *testing.T){ + res,err := SCard("test_article") + + t.Log(res) + t.Log(err) +} \ No newline at end of file