Browse Source

增加调用方法

master v0.4.2
guzeng 2 years ago
parent
commit
3f3325e46f
5 changed files with 106 additions and 2 deletions
  1. +6
    -1
      conn.go
  2. +1
    -1
      go.mod
  3. +2
    -0
      go.sum
  4. +76
    -0
      set.go
  5. +21
    -0
      set_test.go

+ 6
- 1
conn.go View File

@ -8,10 +8,15 @@ import (
func Conn(url ...string) (*RedisServiceClient, *rpc.Client, error) {
var rpc_url string = "127.0.0.1:" + conf.REDIS_RPC_PORT
var rpc_url string
if len(url) > 0 && url[0] != "" {
rpc_url = url[0]
} else if conf.REDIS_RPC_URL != "" {
rpc_url = conf.REDIS_RPC_URL
} else {
rpc_url = "127.0.0.1:" + conf.REDIS_RPC_PORT
}
return DialRedisService("tcp", rpc_url)
}

+ 1
- 1
go.mod View File

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

+ 2
- 0
go.sum View File

@ -1,5 +1,7 @@
git.tetele.net/tgo/conf v0.25.0 h1:fopDch45xw/di5fLvvzwltFiGiXrilMobZwQNO678Wo=
git.tetele.net/tgo/conf v0.25.0/go.mod h1:DogEBvxG2fGdukpoobTVFE2b4Fd5OTE9FJ3Xetyn47E=
git.tetele.net/tgo/conf v0.35.3 h1:OQEa87qN5bAbscjMhaoTRinLnv8xZg1WErl5JXgFZco=
git.tetele.net/tgo/conf v0.35.3/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A=
github.com/chai2010/protorpc v1.0.0 h1:aJ45G9sl1utSKo35EqnBSTs5jqTpdJDJAuZMMYPAtFo=
github.com/chai2010/protorpc v1.0.0/go.mod h1:woR3WwjaQDqFjlzdVsFEKiK5Ur12QL8mYxVPjfr5z54=
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=


+ 76
- 0
set.go View File

@ -0,0 +1,76 @@
package redisrpc
import (
"github.com/golang/protobuf/proto"
)
//设置
func SAdd(key, field string, url ...string) (int64, error) {
conn, _, err := Conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
req := &SSetRequest{proto.String(key), proto.String(field), nil}
res := &SSetResponse{}
err = conn.SAdd(req, res)
if err != nil {
return 0, err
}
return res.GetRet(), nil
}
//删除
func SRem(key string, field string, url ...string) (int64, error) {
conn, _, err := Conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
req := &SSetRequest{proto.String(key), proto.String(field), nil}
res := &SSetResponse{}
err = conn.SRem(req, res)
if err != nil {
return 0, err
}
return res.GetRet(), nil
}
/**
* 全部
*/
func SIsmember(key string, field string, url ...string) (int64, error) {
conn, _, err := Conn(url...)
if err != nil {
return 0, err
}
defer conn.Close()
req := &SSetRequest{proto.String(key), proto.String(field), nil}
res := &SSetResponse{}
err = conn.SIsmember(req, res)
if err != nil {
return 0, err
}
return res.GetRet(), nil
}

+ 21
- 0
set_test.go View File

@ -0,0 +1,21 @@
package redisrpc
import (
// "strconv"
"testing"
// "tgo/helper"
)
func Test_SAdd(t *testing.T) {
// reply, err := SAdd("test", "44")
reply, err := SIsmember("test", "44")
t.Log(reply)
t.Log(err)
reply, err = SRem("test", "44")
t.Log(reply)
t.Log(err)
}

Loading…
Cancel
Save