Skip to content

Commit 310b7f3

Browse files
committed
Merge remote-tracking branch 'upstream/master'
# Conflicts: # client.go # client_test.go
2 parents 4040093 + b4e2818 commit 310b7f3

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

client.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,30 @@ func (client *Client) Info(key string) (info map[string]int64, err error) {
108108
return info, nil
109109
}
110110

111+
// BfAddMulti - Adds one or more items to the Bloom Filter, creating the filter if it does not yet exist.
112+
// args:
113+
// key - the name of the filter
114+
// item - One or more items to add
115+
func (client *Client) BfAddMulti(key string, items []string) ([]int64, error) {
116+
conn := client.Pool.Get()
117+
defer conn.Close()
118+
args := redis.Args{key}.AddFlat(items)
119+
result, err := conn.Do("BF.MADD", args...)
120+
return redis.Int64s(result, err)
121+
}
122+
123+
// BfExistsMulti - Determines if one or more items may exist in the filter or not.
124+
// args:
125+
// key - the name of the filter
126+
// item - one or more items to check
127+
func (client *Client) BfExistsMulti(key string, items []string) ([]int64, error) {
128+
conn := client.Pool.Get()
129+
defer conn.Close()
130+
args := redis.Args{key}.AddFlat(items)
131+
result, err := conn.Do("BF.MEXISTS", args...)
132+
return redis.Int64s(result, err)
133+
}
134+
111135
// Initializes a TopK with specified parameters.
112136
func (client *Client) TopkReserve(key string, topk int64, width int64, depth int64, decay float64) (string, error) {
113137
conn := client.Pool.Get()

client_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ func TestExists(t *testing.T) {
108108
assert.False(t, exists)
109109
}
110110

111+
func TestClient_BfAddMulti(t *testing.T) {
112+
client.FlushAll()
113+
ret, err := client.BfAddMulti("test_add_multi", []string{"a", "b", "c"})
114+
assert.Nil(t, err)
115+
assert.NotNil(t, ret)
116+
}
117+
118+
func TestClient_BfExistsMulti(t *testing.T) {
119+
client.FlushAll()
120+
key := "test_exists_multi"
121+
ret, err := client.BfAddMulti(key, []string{"a", "b", "c"})
122+
assert.Nil(t, err)
123+
assert.NotNil(t, ret)
124+
125+
existsResult, err := client.BfExistsMulti(key, []string{"a", "b", "notexists"})
126+
assert.Nil(t, err)
127+
assert.Equal(t, 3, len(existsResult))
128+
assert.Equal(t, int64(1), existsResult[0])
129+
assert.Equal(t, int64(1), existsResult[1])
130+
assert.Equal(t, int64(0), existsResult[2])
131+
}
132+
111133
func TestClient_TopkReserve(t *testing.T) {
112134
client.FlushAll()
113135
ret, err := client.TopkReserve("test_topk_reserve", 10, 2000, 7, 0.925)

0 commit comments

Comments
 (0)