Browse Source

client for watch

master
guzeng 2 years ago
parent
commit
4daaf09687
2 changed files with 54 additions and 0 deletions
  1. +24
    -0
      watch_test.go
  2. +30
    -0
      wath.go

+ 24
- 0
watch_test.go View File

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

+ 30
- 0
wath.go View File

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

Loading…
Cancel
Save