odb_example.go 965 B

123456789101112131415161718192021222324252627282930313233343536
  1. package main
  2. import (
  3. "context"
  4. "git.wecise.com/wecise/odb-go/odb"
  5. "log"
  6. "time"
  7. )
  8. func main() {
  9. log.SetFlags(log.LstdFlags | log.Lshortfile)
  10. client, err := odb.NewClient(&odb.Config{
  11. Keyspace: "matrix",
  12. //Hosts: []string{"127.0.0.1:11001"},
  13. Hosts: []string{"172.26.38.247:11001"},
  14. //Hosts: []string{"47.92.151.165:11001"},
  15. })
  16. if err != nil {
  17. log.Fatal(err)
  18. }
  19. start := time.Now()
  20. ctx, cancel := context.WithTimeout(context.Background(), time.Second*120)
  21. defer cancel()
  22. _, err = client.Query(`update /matrix/devops/alert set status = 10 where biz = 'test';
  23. select biz, src, id, status, ctime, vtime from /matrix/devops/alert where biz = 'test' and host = 'test' and status = 10 order by ctime limit -1;`).WithContext(ctx).Do() // mql
  24. if err != nil {
  25. log.Println(time.Now().Sub(start).Seconds())
  26. log.Fatal(err)
  27. }
  28. log.Println(time.Now().Sub(start).Seconds())
  29. //for _, d := range res.Data {
  30. // log.Println(d["id"])
  31. //}
  32. }