forked from mirror/redis
commands.go: Add new functions to cluster.
This commit is contained in:
parent
9b1148903e
commit
cbc5360e78
|
@ -230,9 +230,53 @@ var _ = Describe("Cluster", func() {
|
|||
})
|
||||
|
||||
It("should CLUSTER KEYSLOT", func() {
|
||||
res, err := cluster.primary().ClusterKeySlot("somekey").Result()
|
||||
hashSlot, err := cluster.primary().ClusterKeySlot("somekey").Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal(int64(11058)))
|
||||
Expect(hashSlot).To(Equal(int64(11058)))
|
||||
})
|
||||
|
||||
It("should CLUSTER COUNT-FAILURE-REPORTS", func() {
|
||||
n, err := cluster.primary().ClusterCountFailureReports(cluster.nodeIds[0]).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(n).To(Equal(int64(0)))
|
||||
})
|
||||
|
||||
It("should CLUSTER COUNTKEYSINSLOT", func() {
|
||||
n, err := cluster.primary().ClusterCountKeysInSlot(10).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(n).To(Equal(int64(0)))
|
||||
})
|
||||
|
||||
It("should CLUSTER DELSLOTS", func() {
|
||||
res, err := cluster.primary().ClusterDelSlotsRange(16000, 16384-1).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal("OK"))
|
||||
cluster.primary().ClusterAddSlotsRange(16000, 16384-1)
|
||||
})
|
||||
|
||||
It("should CLUSTER SAVECONFIG", func() {
|
||||
res, err := cluster.primary().ClusterSaveConfig().Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal("OK"))
|
||||
})
|
||||
|
||||
It("should CLUSTER SLAVES", func() {
|
||||
nodesList, err := cluster.primary().ClusterSlaves(cluster.nodeIds[0]).Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(nodesList).Should(ContainElement(ContainSubstring("slave")))
|
||||
Expect(nodesList).Should(HaveLen(1))
|
||||
})
|
||||
|
||||
It("should CLUSTER READONLY", func() {
|
||||
res, err := cluster.primary().Readonly().Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal("OK"))
|
||||
})
|
||||
|
||||
It("should CLUSTER READWRITE", func() {
|
||||
res, err := cluster.primary().ReadWrite().Result()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(res).To(Equal("OK"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
62
commands.go
62
commands.go
|
@ -1705,6 +1705,68 @@ func (c *commandable) ClusterKeySlot(key string) *IntCmd {
|
|||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterCountFailureReports(nodeID string) *IntCmd {
|
||||
cmd := NewIntCmd("CLUSTER", "count-failure-reports", nodeID)
|
||||
cmd._clusterKeyPos = 2
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterCountKeysInSlot(slot int) *IntCmd {
|
||||
cmd := NewIntCmd("CLUSTER", "countkeysinslot", slot)
|
||||
cmd._clusterKeyPos = 2
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterDelSlots(slots ...int) *StatusCmd {
|
||||
args := make([]interface{}, 2+len(slots))
|
||||
args[0] = "CLUSTER"
|
||||
args[1] = "DELSLOTS"
|
||||
for i, slot := range slots {
|
||||
args[2+i] = slot
|
||||
}
|
||||
cmd := newKeylessStatusCmd(args...)
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterDelSlotsRange(min, max int) *StatusCmd {
|
||||
size := max - min + 1
|
||||
slots := make([]int, size)
|
||||
for i := 0; i < size; i++ {
|
||||
slots[i] = min + i
|
||||
}
|
||||
return c.ClusterDelSlots(slots...)
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterSaveConfig() *StatusCmd {
|
||||
cmd := newKeylessStatusCmd("CLUSTER", "saveconfig")
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterSlaves(nodeID string) *StringSliceCmd {
|
||||
cmd := NewStringSliceCmd("CLUSTER", "SLAVES", nodeID)
|
||||
cmd._clusterKeyPos = 2
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) Readonly() *StatusCmd {
|
||||
cmd := newKeylessStatusCmd("READONLY")
|
||||
cmd._clusterKeyPos = 0
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ReadWrite() *StatusCmd {
|
||||
cmd := newKeylessStatusCmd("READWRITE")
|
||||
cmd._clusterKeyPos = 0
|
||||
c.Process(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (c *commandable) ClusterFailover() *StatusCmd {
|
||||
cmd := newKeylessStatusCmd("CLUSTER", "failover")
|
||||
c.Process(cmd)
|
||||
|
|
Loading…
Reference in New Issue