main.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package main
  2. import (
  3. "context"
  4. "encoding/binary"
  5. "flag"
  6. "fmt"
  7. rpc "go-common/app/service/bbq/recsys/api/grpc/v1"
  8. "go-common/library/cache/redis"
  9. "go-common/library/container/pool"
  10. "go-common/library/net/rpc/warden"
  11. xtime "go-common/library/time"
  12. "log"
  13. "time"
  14. "github.com/Dai0522/go-hash/bloomfilter"
  15. )
  16. var name, addr string
  17. func init() {
  18. flag.StringVar(&name, "name", "lily", "name")
  19. flag.StringVar(&addr, "addr", "127.0.0.1:9000", "server addr")
  20. }
  21. func bf(svid int64) {
  22. conf := &redis.Config{
  23. Config: &pool.Config{
  24. Active: 10,
  25. Idle: 10,
  26. },
  27. Name: "recsys-service.user_profile",
  28. Proto: "tcp",
  29. Addr: "172.16.38.91:6379",
  30. WriteTimeout: xtime.Duration(1 * time.Second),
  31. DialTimeout: xtime.Duration(1 * time.Second),
  32. ReadTimeout: xtime.Duration(1 * time.Second),
  33. }
  34. rp := redis.NewPool(conf)
  35. conn := rp.Get(context.Background())
  36. defer conn.Close()
  37. b, _ := redis.Bytes(conn.Do("GET", "BBQ:BF:V1:5829468"))
  38. if b != nil {
  39. bf, _ := bloomfilter.Load(&b)
  40. tmp := make([]byte, 8)
  41. binary.LittleEndian.PutUint64(tmp, uint64(svid))
  42. fmt.Println(bf.MightContain(tmp))
  43. }
  44. }
  45. func main() {
  46. flag.Parse()
  47. cfg := &warden.ClientConfig{
  48. Dial: xtime.Duration(time.Second * 3),
  49. Timeout: xtime.Duration(time.Second * 3),
  50. }
  51. cc, err := warden.NewClient(cfg).Dial(context.Background(), addr)
  52. if err != nil {
  53. log.Fatalf("new client failed!err:=%v", err)
  54. return
  55. }
  56. var MID int64 = 5829468 // 10022647 //100011563
  57. buvID := "d9972de637d2f3b8939ee628a7ea789b"
  58. client := rpc.NewRecsysClient(cc)
  59. resp, err := client.RecService(context.Background(), &rpc.RecsysRequest{
  60. MID: MID,
  61. BUVID: buvID,
  62. Limit: 5,
  63. DebugFlag: true,
  64. DebugType: "rank",
  65. })
  66. if err != nil {
  67. log.Fatalf("say hello failed!err:=%v", err)
  68. return
  69. }
  70. fmt.Printf("got Reply: %+v", resp)
  71. for _, v := range resp.List {
  72. fmt.Println(v.Svid)
  73. bf(v.Svid)
  74. }
  75. }