Skip to content

Commit

Permalink
Merge pull request redis#183 from lcosmin/master
Browse files Browse the repository at this point in the history
Implemented PFADD, PFCOUNT, PFMERGE
  • Loading branch information
vmihailenco committed Nov 4, 2015
2 parents 05394be + 43603e1 commit a2dba7d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
32 changes: 32 additions & 0 deletions commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit a2dba7d

Please sign in to comment.