From 4daaf096875575ebff8df5e801b342eae684f6ab Mon Sep 17 00:00:00 2001 From: guzeng Date: Tue, 30 Nov 2021 11:23:45 +0800 Subject: [PATCH] client for watch --- watch_test.go | 24 ++++++++++++++++++++++++ wath.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 watch_test.go create mode 100644 wath.go diff --git a/watch_test.go b/watch_test.go new file mode 100644 index 0000000..7ecc527 --- /dev/null +++ b/watch_test.go @@ -0,0 +1,24 @@ +package redisrpc + +import ( + "log" + "testing" + // "time" +) + +func Test_ReduceStock(t *testing.T) { + + ch := make(chan int) + for i := 0; i < 100; i++ { + go func() { + log.Println("start") + + reply, err := ReduceStock("test_watch", "2") + + log.Println(reply) + log.Println(err) + log.Println("end") + }() + } + <-ch +} diff --git a/wath.go b/wath.go new file mode 100644 index 0000000..5468ac2 --- /dev/null +++ b/wath.go @@ -0,0 +1,30 @@ +package redisrpc + +import ( + "github.com/golang/protobuf/proto" +) + +/** + * 使用用户名查询 + */ +func ReduceStock(key string, value string, url ...string) (string, error) { + + conn, _, err := Conn(url...) + + if err != nil { + return "", err + } + defer conn.Close() + + req := &SetRequest{proto.String(key), proto.String(value), proto.Int64(0), nil} + + res := &SetResponse{} + + err = conn.ReduceStock(req, res) + + if err != nil { + return "", err + } + + return res.GetRet(), nil +}