result.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package redis
  2. import "time"
  3. // NewCmdResult returns a Cmd initalised with val and err for testing
  4. func NewCmdResult(val interface{}, err error) *Cmd {
  5. var cmd Cmd
  6. cmd.val = val
  7. cmd.setErr(err)
  8. return &cmd
  9. }
  10. // NewSliceResult returns a SliceCmd initalised with val and err for testing
  11. func NewSliceResult(val []interface{}, err error) *SliceCmd {
  12. var cmd SliceCmd
  13. cmd.val = val
  14. cmd.setErr(err)
  15. return &cmd
  16. }
  17. // NewStatusResult returns a StatusCmd initalised with val and err for testing
  18. func NewStatusResult(val string, err error) *StatusCmd {
  19. var cmd StatusCmd
  20. cmd.val = val
  21. cmd.setErr(err)
  22. return &cmd
  23. }
  24. // NewIntResult returns an IntCmd initalised with val and err for testing
  25. func NewIntResult(val int64, err error) *IntCmd {
  26. var cmd IntCmd
  27. cmd.val = val
  28. cmd.setErr(err)
  29. return &cmd
  30. }
  31. // NewDurationResult returns a DurationCmd initalised with val and err for testing
  32. func NewDurationResult(val time.Duration, err error) *DurationCmd {
  33. var cmd DurationCmd
  34. cmd.val = val
  35. cmd.setErr(err)
  36. return &cmd
  37. }
  38. // NewBoolResult returns a BoolCmd initalised with val and err for testing
  39. func NewBoolResult(val bool, err error) *BoolCmd {
  40. var cmd BoolCmd
  41. cmd.val = val
  42. cmd.setErr(err)
  43. return &cmd
  44. }
  45. // NewStringResult returns a StringCmd initalised with val and err for testing
  46. func NewStringResult(val string, err error) *StringCmd {
  47. var cmd StringCmd
  48. cmd.val = []byte(val)
  49. cmd.setErr(err)
  50. return &cmd
  51. }
  52. // NewFloatResult returns a FloatCmd initalised with val and err for testing
  53. func NewFloatResult(val float64, err error) *FloatCmd {
  54. var cmd FloatCmd
  55. cmd.val = val
  56. cmd.setErr(err)
  57. return &cmd
  58. }
  59. // NewStringSliceResult returns a StringSliceCmd initalised with val and err for testing
  60. func NewStringSliceResult(val []string, err error) *StringSliceCmd {
  61. var cmd StringSliceCmd
  62. cmd.val = val
  63. cmd.setErr(err)
  64. return &cmd
  65. }
  66. // NewBoolSliceResult returns a BoolSliceCmd initalised with val and err for testing
  67. func NewBoolSliceResult(val []bool, err error) *BoolSliceCmd {
  68. var cmd BoolSliceCmd
  69. cmd.val = val
  70. cmd.setErr(err)
  71. return &cmd
  72. }
  73. // NewStringStringMapResult returns a StringStringMapCmd initalised with val and err for testing
  74. func NewStringStringMapResult(val map[string]string, err error) *StringStringMapCmd {
  75. var cmd StringStringMapCmd
  76. cmd.val = val
  77. cmd.setErr(err)
  78. return &cmd
  79. }
  80. // NewStringIntMapCmdResult returns a StringIntMapCmd initalised with val and err for testing
  81. func NewStringIntMapCmdResult(val map[string]int64, err error) *StringIntMapCmd {
  82. var cmd StringIntMapCmd
  83. cmd.val = val
  84. cmd.setErr(err)
  85. return &cmd
  86. }
  87. // NewZSliceCmdResult returns a ZSliceCmd initalised with val and err for testing
  88. func NewZSliceCmdResult(val []Z, err error) *ZSliceCmd {
  89. var cmd ZSliceCmd
  90. cmd.val = val
  91. cmd.setErr(err)
  92. return &cmd
  93. }
  94. // NewScanCmdResult returns a ScanCmd initalised with val and err for testing
  95. func NewScanCmdResult(keys []string, cursor uint64, err error) *ScanCmd {
  96. var cmd ScanCmd
  97. cmd.page = keys
  98. cmd.cursor = cursor
  99. cmd.setErr(err)
  100. return &cmd
  101. }
  102. // NewClusterSlotsCmdResult returns a ClusterSlotsCmd initalised with val and err for testing
  103. func NewClusterSlotsCmdResult(val []ClusterSlot, err error) *ClusterSlotsCmd {
  104. var cmd ClusterSlotsCmd
  105. cmd.val = val
  106. cmd.setErr(err)
  107. return &cmd
  108. }
  109. // NewGeoLocationCmdResult returns a GeoLocationCmd initalised with val and err for testing
  110. func NewGeoLocationCmdResult(val []GeoLocation, err error) *GeoLocationCmd {
  111. var cmd GeoLocationCmd
  112. cmd.locations = val
  113. cmd.setErr(err)
  114. return &cmd
  115. }
  116. // NewCommandsInfoCmdResult returns a CommandsInfoCmd initalised with val and err for testing
  117. func NewCommandsInfoCmdResult(val map[string]*CommandInfo, err error) *CommandsInfoCmd {
  118. var cmd CommandsInfoCmd
  119. cmd.val = val
  120. cmd.setErr(err)
  121. return &cmd
  122. }