diff --git a/commands.go b/commands.go index 9a65d66..694cf4e 100644 --- a/commands.go +++ b/commands.go @@ -1332,6 +1332,38 @@ func (c *commandable) ZUnionStore(dest string, store ZStore, keys ...string) *In //------------------------------------------------------------------------------ +func (c *commandable) PFAdd(key string, fields ...string) *IntCmd { + args := make([]interface{}, 2+len(fields)) + args[0] = "PFADD" + args[1] = key + for i, field := range fields { + args[2+i] = field + } + cmd := NewIntCmd(args...) + c.Process(cmd) + return cmd +} + +func (c *commandable) PFCount(key string) *IntCmd { + cmd := NewIntCmd("PFCOUNT", key) + c.Process(cmd) + return cmd +} + +func (c *commandable) PFMerge(dest string, keys ...string) *StatusCmd { + args := make([]interface{}, 2+len(keys)) + args[0] = "PFMERGE" + args[1] = dest + for i, key := range keys { + args[2+i] = key + } + cmd := NewStatusCmd(args...) + c.Process(cmd) + return cmd +} + +//------------------------------------------------------------------------------ + func (c *commandable) BgRewriteAOF() *StatusCmd { cmd := NewStatusCmd("BGREWRITEAOF") cmd._clusterKeyPos = 0 diff --git a/commands_test.go b/commands_test.go index f7fd42e..3304a1e 100644 --- a/commands_test.go +++ b/commands_test.go @@ -1190,6 +1190,27 @@ var _ = Describe("Commands", func() { }) + Describe("hyperloglog", func() { + It("should PFMerge", func() { + pfAdd := client.PFAdd("hll1", "1", "2", "3", "4", "5") + Expect(pfAdd.Err()).NotTo(HaveOccurred()) + + pfCount := client.PFCount("hll1") + Expect(pfCount.Err()).NotTo(HaveOccurred()) + Expect(pfCount.Val()).To(Equal(int64(5))) + + pfAdd = client.PFAdd("hll2", "a", "b", "c", "d", "e") + Expect(pfAdd.Err()).NotTo(HaveOccurred()) + + pfMerge := client.PFMerge("hllMerged", "hll1", "hll2") + Expect(pfMerge.Err()).NotTo(HaveOccurred()) + + pfCount = client.PFCount("hllMerged") + Expect(pfCount.Err()).NotTo(HaveOccurred()) + Expect(pfCount.Val()).To(Equal(int64(10))) + }) + }) + Describe("lists", func() { It("should BLPop", func() {