You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 line
5.7 KiB

  1. package redis
  2. import "context"
  3. type ClusterCmdable interface {
  4. ClusterMyShardID(ctx context.Context) *StringCmd
  5. ClusterMyID(ctx context.Context) *StringCmd
  6. ClusterSlots(ctx context.Context) *ClusterSlotsCmd
  7. ClusterShards(ctx context.Context) *ClusterShardsCmd
  8. ClusterLinks(ctx context.Context) *ClusterLinksCmd
  9. ClusterNodes(ctx context.Context) *StringCmd
  10. ClusterMeet(ctx context.Context, host, port string) *StatusCmd
  11. ClusterForget(ctx context.Context, nodeID string) *StatusCmd
  12. ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd
  13. ClusterResetSoft(ctx context.Context) *StatusCmd
  14. ClusterResetHard(ctx context.Context) *StatusCmd
  15. ClusterInfo(ctx context.Context) *StringCmd
  16. ClusterKeySlot(ctx context.Context, key string) *IntCmd
  17. ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd
  18. ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd
  19. ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd
  20. ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd
  21. ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd
  22. ClusterSaveConfig(ctx context.Context) *StatusCmd
  23. ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd
  24. ClusterFailover(ctx context.Context) *StatusCmd
  25. ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd
  26. ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd
  27. ReadOnly(ctx context.Context) *StatusCmd
  28. ReadWrite(ctx context.Context) *StatusCmd
  29. }
  30. func (c cmdable) ClusterMyShardID(ctx context.Context) *StringCmd {
  31. cmd := NewStringCmd(ctx, "cluster", "myshardid")
  32. _ = c(ctx, cmd)
  33. return cmd
  34. }
  35. func (c cmdable) ClusterMyID(ctx context.Context) *StringCmd {
  36. cmd := NewStringCmd(ctx, "cluster", "myid")
  37. _ = c(ctx, cmd)
  38. return cmd
  39. }
  40. func (c cmdable) ClusterSlots(ctx context.Context) *ClusterSlotsCmd {
  41. cmd := NewClusterSlotsCmd(ctx, "cluster", "slots")
  42. _ = c(ctx, cmd)
  43. return cmd
  44. }
  45. func (c cmdable) ClusterShards(ctx context.Context) *ClusterShardsCmd {
  46. cmd := NewClusterShardsCmd(ctx, "cluster", "shards")
  47. _ = c(ctx, cmd)
  48. return cmd
  49. }
  50. func (c cmdable) ClusterLinks(ctx context.Context) *ClusterLinksCmd {
  51. cmd := NewClusterLinksCmd(ctx, "cluster", "links")
  52. _ = c(ctx, cmd)
  53. return cmd
  54. }
  55. func (c cmdable) ClusterNodes(ctx context.Context) *StringCmd {
  56. cmd := NewStringCmd(ctx, "cluster", "nodes")
  57. _ = c(ctx, cmd)
  58. return cmd
  59. }
  60. func (c cmdable) ClusterMeet(ctx context.Context, host, port string) *StatusCmd {
  61. cmd := NewStatusCmd(ctx, "cluster", "meet", host, port)
  62. _ = c(ctx, cmd)
  63. return cmd
  64. }
  65. func (c cmdable) ClusterForget(ctx context.Context, nodeID string) *StatusCmd {
  66. cmd := NewStatusCmd(ctx, "cluster", "forget", nodeID)
  67. _ = c(ctx, cmd)
  68. return cmd
  69. }
  70. func (c cmdable) ClusterReplicate(ctx context.Context, nodeID string) *StatusCmd {
  71. cmd := NewStatusCmd(ctx, "cluster", "replicate", nodeID)
  72. _ = c(ctx, cmd)
  73. return cmd
  74. }
  75. func (c cmdable) ClusterResetSoft(ctx context.Context) *StatusCmd {
  76. cmd := NewStatusCmd(ctx, "cluster", "reset", "soft")
  77. _ = c(ctx, cmd)
  78. return cmd
  79. }
  80. func (c cmdable) ClusterResetHard(ctx context.Context) *StatusCmd {
  81. cmd := NewStatusCmd(ctx, "cluster", "reset", "hard")
  82. _ = c(ctx, cmd)
  83. return cmd
  84. }
  85. func (c cmdable) ClusterInfo(ctx context.Context) *StringCmd {
  86. cmd := NewStringCmd(ctx, "cluster", "info")
  87. _ = c(ctx, cmd)
  88. return cmd
  89. }
  90. func (c cmdable) ClusterKeySlot(ctx context.Context, key string) *IntCmd {
  91. cmd := NewIntCmd(ctx, "cluster", "keyslot", key)
  92. _ = c(ctx, cmd)
  93. return cmd
  94. }
  95. func (c cmdable) ClusterGetKeysInSlot(ctx context.Context, slot int, count int) *StringSliceCmd {
  96. cmd := NewStringSliceCmd(ctx, "cluster", "getkeysinslot", slot, count)
  97. _ = c(ctx, cmd)
  98. return cmd
  99. }
  100. func (c cmdable) ClusterCountFailureReports(ctx context.Context, nodeID string) *IntCmd {
  101. cmd := NewIntCmd(ctx, "cluster", "count-failure-reports", nodeID)
  102. _ = c(ctx, cmd)
  103. return cmd
  104. }
  105. func (c cmdable) ClusterCountKeysInSlot(ctx context.Context, slot int) *IntCmd {
  106. cmd := NewIntCmd(ctx, "cluster", "countkeysinslot", slot)
  107. _ = c(ctx, cmd)
  108. return cmd
  109. }
  110. func (c cmdable) ClusterDelSlots(ctx context.Context, slots ...int) *StatusCmd {
  111. args := make([]interface{}, 2+len(slots))
  112. args[0] = "cluster"
  113. args[1] = "delslots"
  114. for i, slot := range slots {
  115. args[2+i] = slot
  116. }
  117. cmd := NewStatusCmd(ctx, args...)
  118. _ = c(ctx, cmd)
  119. return cmd
  120. }
  121. func (c cmdable) ClusterDelSlotsRange(ctx context.Context, min, max int) *StatusCmd {
  122. size := max - min + 1
  123. slots := make([]int, size)
  124. for i := 0; i < size; i++ {
  125. slots[i] = min + i
  126. }
  127. return c.ClusterDelSlots(ctx, slots...)
  128. }
  129. func (c cmdable) ClusterSaveConfig(ctx context.Context) *StatusCmd {
  130. cmd := NewStatusCmd(ctx, "cluster", "saveconfig")
  131. _ = c(ctx, cmd)
  132. return cmd
  133. }
  134. func (c cmdable) ClusterSlaves(ctx context.Context, nodeID string) *StringSliceCmd {
  135. cmd := NewStringSliceCmd(ctx, "cluster", "slaves", nodeID)
  136. _ = c(ctx, cmd)
  137. return cmd
  138. }
  139. func (c cmdable) ClusterFailover(ctx context.Context) *StatusCmd {
  140. cmd := NewStatusCmd(ctx, "cluster", "failover")
  141. _ = c(ctx, cmd)
  142. return cmd
  143. }
  144. func (c cmdable) ClusterAddSlots(ctx context.Context, slots ...int) *StatusCmd {
  145. args := make([]interface{}, 2+len(slots))
  146. args[0] = "cluster"
  147. args[1] = "addslots"
  148. for i, num := range slots {
  149. args[2+i] = num
  150. }
  151. cmd := NewStatusCmd(ctx, args...)
  152. _ = c(ctx, cmd)
  153. return cmd
  154. }
  155. func (c cmdable) ClusterAddSlotsRange(ctx context.Context, min, max int) *StatusCmd {
  156. size := max - min + 1
  157. slots := make([]int, size)
  158. for i := 0; i < size; i++ {
  159. slots[i] = min + i
  160. }
  161. return c.ClusterAddSlots(ctx, slots...)
  162. }
  163. func (c cmdable) ReadOnly(ctx context.Context) *StatusCmd {
  164. cmd := NewStatusCmd(ctx, "readonly")
  165. _ = c(ctx, cmd)
  166. return cmd
  167. }
  168. func (c cmdable) ReadWrite(ctx context.Context) *StatusCmd {
  169. cmd := NewStatusCmd(ctx, "readwrite")
  170. _ = c(ctx, cmd)
  171. return cmd
  172. }