Browse Source

增加scard方法

master v0.7.3
listen 3 years ago
parent
commit
792d021307
3 changed files with 33 additions and 7 deletions
  1. +0
    -7
      num_test.go
  2. +26
    -0
      set.go
  3. +7
    -0
      set_test.go

+ 0
- 7
num_test.go View File

@ -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) {


+ 26
- 0
set.go View File

@ -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
}

+ 7
- 0
set_test.go View File

@ -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)
}

Loading…
Cancel
Save