From 0a7606651d026c521a6b51b2e947cbf58535a183 Mon Sep 17 00:00:00 2001 From: Vladimir Mihailenco Date: Mon, 11 Sep 2017 09:19:30 +0300 Subject: [PATCH] Add Cluster.DBSize --- cluster_commands.go | 22 ++++++++++++++++++++++ cluster_test.go | 8 +++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 cluster_commands.go diff --git a/cluster_commands.go b/cluster_commands.go new file mode 100644 index 0000000..dff62c9 --- /dev/null +++ b/cluster_commands.go @@ -0,0 +1,22 @@ +package redis + +import "sync/atomic" + +func (c *ClusterClient) DBSize() *IntCmd { + cmd := NewIntCmd("dbsize") + var size int64 + err := c.ForEachMaster(func(master *Client) error { + n, err := master.DBSize().Result() + if err != nil { + return err + } + atomic.AddInt64(&size, n) + return nil + }) + if err != nil { + cmd.setErr(err) + return cmd + } + cmd.val = size + return cmd +} diff --git a/cluster_test.go b/cluster_test.go index b2106da..6f3677b 100644 --- a/cluster_test.go +++ b/cluster_test.go @@ -475,11 +475,9 @@ var _ = Describe("ClusterClient", func() { }) Expect(err).NotTo(HaveOccurred()) - for _, client := range cluster.masters() { - size, err := client.DBSize().Result() - Expect(err).NotTo(HaveOccurred()) - Expect(size).To(Equal(int64(0))) - } + size, err := client.DBSize().Result() + Expect(err).NotTo(HaveOccurred()) + Expect(size).To(Equal(int64(0))) }) It("should CLUSTER SLOTS", func() {