cmd_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package odb
  2. import (
  3. "testing"
  4. "time"
  5. "github.com/gomodule/redigo/redis"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. "github.com/vmihailenco/msgpack/v5"
  9. )
  10. func dial() (redis.Conn, error) {
  11. //c, err := redis.Dial("tcp", "172.26.38.247:11001")
  12. c, err := redis.Dial("tcp", "127.0.0.1:11001")
  13. //c, err := redis.Dial("tcp", "172.20.147.7:11001")
  14. if err != nil {
  15. return nil, err
  16. }
  17. return c, nil
  18. }
  19. func Test_1(t *testing.T) {
  20. c, err := dial()
  21. assert.Nil(t, err, "Error")
  22. defer c.Close()
  23. reply, err := redis.DoWithTimeout(c, 1200*time.Second, "create", "testoo", "REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1}")
  24. require.Nil(t, err, "Error")
  25. t.Logf("reply ==>%v \n", string(reply.([]byte)))
  26. }
  27. func Test_2(t *testing.T) {
  28. c, err := dial()
  29. assert.Nil(t, err, "Error")
  30. defer c.Close()
  31. option, _ := msgpack.Marshal(map[string]interface{}{"db": "testoo", "asterisk_keep": []string{"class", "id"}})
  32. reply, err := c.Do("MQL", ` select * from MillingCuttingTool where id = "MillingCuttingTool:1002"; `, option)
  33. require.Nil(t, err, "Error")
  34. t.Logf("reply ==>%v \n", string(reply.([]byte)))
  35. }
  36. func Test_3(t *testing.T) {
  37. c, err := dial()
  38. assert.Nil(t, err, "Error")
  39. defer c.Close()
  40. option, _ := msgpack.Marshal(map[string]interface{}{"db": "matrix", "asterisk_keep": []string{"class", "id"}})
  41. reply, err := c.Do("MQL", ` select * from MillingCuttingTool where id = "MillingCuttingTool:1002"; `, option)
  42. require.Nil(t, err, "Error")
  43. t.Logf("reply ==>%v \n", string(reply.([]byte)))
  44. }