diff --git a/conn.go b/conn.go index b5ecadd..d4e7d2e 100644 --- a/conn.go +++ b/conn.go @@ -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) + } diff --git a/go.mod b/go.mod index df3f1ed..82ea8b2 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 + git.tetele.net/tgo/conf v0.35.3 github.com/chai2010/protorpc v1.0.0 github.com/golang/protobuf v1.5.2 ) diff --git a/go.sum b/go.sum index 778c639..ef593ba 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/set.go b/set.go new file mode 100644 index 0000000..6c86056 --- /dev/null +++ b/set.go @@ -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 +} diff --git a/set_test.go b/set_test.go new file mode 100644 index 0000000..be10b2f --- /dev/null +++ b/set_test.go @@ -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) + +}