testcmd.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package main
  2. import (
  3. //"os"
  4. "fmt"
  5. //"time"
  6. //"encoding/json"
  7. //"runtime/pprof"
  8. //"git.wecise.com/wecise/util/const/mdir"
  9. "github.com/gomodule/redigo/redis"
  10. "github.com/vmihailenco/msgpack/v5"
  11. //"gitee.com/wecisecode/util/logger"
  12. )
  13. // dial wraps DialDefaultServer() with a more suitable function name for examples.
  14. func dial() (redis.Conn, error) {
  15. //c, err := redis.Dial("tcp", "172.26.38.247:11001")
  16. //c, err := redis.Dial("tcp", "127.0.0.1:11001")
  17. c, err := redis.Dial("tcp", "47.92.151.165:11001")
  18. if err != nil {
  19. return nil, err
  20. }
  21. return c, nil
  22. }
  23. func main() {
  24. c, err := dial()
  25. if err != nil {
  26. fmt.Println(err)
  27. return
  28. }
  29. defer c.Close()
  30. //params, _ := msgpack.Marshal([]interface{}{ "SD25" })
  31. //params, _ := json.Marshal([]interface{}{ "SD25" })
  32. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "matrix" , "user":"/测试部/test01" } )
  33. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "matrix" } )
  34. //reply, err := c.Do("SEARCH", `#/matrix/devops/alert_status | severity > 3 | print severity | top 200`, option)
  35. //params, _ := msgpack.Marshal(map[string]interface{}{ "policy": "dc1:1" })
  36. //reply, err := c.Do("OMDB", "testoo", "create", params )
  37. //reply, err := redis.DoWithTimeout(c, 1200*time.Second, "create", "testoo", "REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}" )
  38. /*params, _ := msgpack.Marshal([]interface{}{ "/matrix/devops/alert" })
  39. reply, err := c.Do("CQL", "select name from class where name=?", params )*/
  40. //params, _ := msgpack.Marshal([]interface{}{"10", "IT10", "11", "IT11", "12", "IT12", "13", "IT13"})
  41. //reply, err := c.Do("SQL", `insert into org values (?, ?)`, "type=table,console=true", params)
  42. //params, _ := msgpack.Marshal([]interface{}{ "07", "IT7"})
  43. //reply, err := c.Do("SQL", `insert into org values (?, ?)`, "type=table,console=true", params)
  44. //params, _ := msgpack.Marshal(nil)
  45. //option, _ := msgpack.Marshal(map[string]interface{}{ "db": "matrix" })
  46. //reply, err := c.Do("CQL", `alter table class add onconflict map<varchar,int>`)
  47. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "matrix" , "search_dirs": []string{"/filesystem"}, "search_class": []string{"/hello"}, "asterisk_no_relation": true } )
  48. //reply, err := c.Do("SEARCH", `devops`, option)
  49. //params, _ := msgpack.Marshal( []interface{} { map[string][]string{ "add": {"/测试部"}, "delete": {"/测试部"}, "edit": {"/测试部"}, "list": {"/测试部"}}, "", "company", []string{ "总行/核心交换机2", "总行/核心交换机", "总行"} } )
  50. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "matrix" , "default_nil": true } )
  51. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "eventbus" , "asterisk_no_relation": true, "asterisk_keep": []string{} } )
  52. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "ootest" , "asterisk_keep": []string{"class", "id"} } )
  53. //params, _ := msgpack.Marshal( []interface{} { nil, nil, nil, nil, nil, "/admin" } )
  54. //reply, err := c.Do("MQL", `update alert_status set type=2 where severity in ?`, option, params )
  55. //reply, err := c.Do("MQL", `update /matrix/tagdir set _group = _group - ? where creater = ? and domain = ? and path in ?`, option, params )
  56. //reply, err := c.Do("MQL", `update group set tadd=tadd+?, tedit=tedit+?, tdelete=tdelete+?, tlist=tlist+?, _group=_group+? where fullname=?`, option, params )
  57. //reply, err := c.Do("MQL", ` insert into /matrix/devops/change (workordernum) values ('test1')`, string(option) )
  58. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "typedeftest", "content": "json", "asterisk_no_relation": true, "asterisk_keep": []string{"id", "class"} } )
  59. //reply, err := c.Do("MQL", ` select * from MillingCuttingTool where id = "MillingCuttingTool:1002"; `, option )
  60. //option, _ := msgpack.Marshal(map[string]interface{}{"meta": false, "content": "json"})
  61. params, _ := msgpack.Marshal([]interface{}{"IBPS", 202301251540, 1})
  62. option, _ := msgpack.Marshal(map[string]interface{}{"db": "ootest", "asterisk_no_relation": true})
  63. reply, err := c.Do("MQL", ` select transuid, appno, comptime, msgdealstatus, atrt from /native/cnccbdos@202301251540 where syscode = ? and minute = ? and batchno = ? `, option, params)
  64. /*st := time.Now().UnixNano()
  65. reply, err := c.Do("SEARCH", `#/matrix/devops/alert_status`)
  66. //reply, err := c.Do("MQL", ` select * from /matrix/devops/alert_status`)
  67. fmt.Printf( fmt.Sprintf("diff ==> %v\n", time.Now().UnixNano()-st) )
  68. */
  69. //reply, err := c.Do("PUBLISH", `test`, "hello")
  70. //reply, err := c.Do("schema", `matrix`, "/matrix/entity/interface")
  71. //reply, err := c.Do("schema", `matrix`, "/")
  72. //option, _ := msgpack.Marshal( map[string]interface{}{ "db": "matrix" } )
  73. /*reply, err := c.Do("MQL", ` create class if not exists /matrix/testddd();
  74. create class if not exists /matrix/testddd/api (
  75. name varchar '权限名称',
  76. pprefix set<varchar> '开头匹配的JS目录权限',
  77. pmatch set<varchar> '完全匹配的JS文件权限',
  78. mtime timestamp '更新时间',
  79. keys(name),
  80. indexes(name, mtime)
  81. ) with partition=name, version=true, key=hash, autosearch=false;
  82. create class if not exists /matrix/testddd/ui (
  83. name varchar 'HTML的上级目录',
  84. app varchar '/app下第一级目录名称,与/matrix/portal/tools的app相同',
  85. perms set<varchar> '权限标签列表',
  86. mtime timestamp '更新时间',
  87. keys(name, app),
  88. indexes(name, app, mtime)
  89. ) with partition=(name,app), version=true, key=hash, autosearch=false; `, option )*/
  90. if err == nil {
  91. fmt.Printf("reply ==>%v \n", string(reply.([]byte)))
  92. } else {
  93. fmt.Printf("error ==>%v \n", err)
  94. }
  95. }